Skip to content

Commit 8825bbf

Browse files
authored
Merge pull request jupyterlab#52 from dhirschfeld/base-url
Add ability to configure the GitHub base url
2 parents 66433b2 + de45c79 commit 8825bbf

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

schema/drive.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"properties": {
77
"defaultRepo": {
88
"type": "string", "title": "Default Repository", "default": ""
9+
},
10+
"baseUrl": {
11+
"type": "string", "title": "The GitHub Base URL", "default": "https://github.com"
912
}
1013
},
1114
"type": "object"

src/browser.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const MY_BINDER_BASE_URL = 'https://mybinder.org/v2/gh';
3838
/**
3939
* The GitHub base url.
4040
*/
41-
const GITHUB_BASE_URL = 'https://github.com';
41+
export const DEFAULT_GITHUB_BASE_URL = 'https://github.com';
4242

4343
/**
4444
* The className for disabling the mybinder button.
@@ -64,12 +64,12 @@ class GitHubFileBrowser extends Widget {
6464
this.userName.node.title = 'Click to edit user/organization';
6565
this._browser.toolbar.addItem('user', this.userName);
6666
this.userName.name.changed.connect(this._onUserChanged, this);
67-
67+
this.baseUrl = DEFAULT_GITHUB_BASE_URL;
6868
// Create a button that opens GitHub at the appropriate
6969
// repo+directory.
7070
this._openGitHubButton = new ToolbarButton({
7171
onClick: () => {
72-
let url = GITHUB_BASE_URL;
72+
let url = this.baseUrl;
7373
// If there is no valid user, open the GitHub homepage.
7474
if (!this._drive.validUser) {
7575
window.open(url);
@@ -117,13 +117,28 @@ class GitHubFileBrowser extends Widget {
117117
this._onPathChanged();
118118

119119
this._drive.rateLimitedState.changed.connect(this._updateErrorPanel, this);
120+
120121
}
121122

122123
/**
123124
* An editable widget hosting the current user name.
124125
*/
125126
readonly userName: GitHubEditableName;
126127

128+
/**
129+
* The GitHub base URL
130+
*/
131+
get baseUrl(): string {
132+
return this._baseUrl;
133+
}
134+
135+
/**
136+
* The GitHub base URL is set by the settingsRegistry change hook
137+
*/
138+
set baseUrl(url: string) {
139+
this._baseUrl = url;
140+
}
141+
127142
/**
128143
* React to a change in user.
129144
*/
@@ -244,6 +259,7 @@ class GitHubFileBrowser extends Widget {
244259

245260
private _browser: FileBrowser;
246261
private _drive: GitHubDrive;
262+
private _baseUrl: string;
247263
private _errorPanel: GitHubErrorPanel | null;
248264
private _openGitHubButton: ToolbarButton;
249265
private _launchBinderButton: ToolbarButton;

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from './contents';
2323

2424
import {
25-
GitHubFileBrowser
25+
GitHubFileBrowser, DEFAULT_GITHUB_BASE_URL
2626
} from './browser';
2727

2828
import '../style/index.css';
@@ -71,9 +71,16 @@ function activateFileBrowser(app: JupyterLab, manager: IDocumentManager, factory
7171
restorer.add(gitHubBrowser, NAMESPACE);
7272
app.shell.addToLeftArea(gitHubBrowser, { rank: 102 });
7373

74+
const onSettingsUpdated = (settings: ISettingRegistry.ISettings) => {
75+
const baseUrl = settings.get('baseUrl').composite as string | null | undefined;
76+
gitHubBrowser.baseUrl = baseUrl || DEFAULT_GITHUB_BASE_URL;
77+
};
78+
7479
// Fetch the initial state of the settings.
7580
Promise.all([settingRegistry.load(PLUGIN_ID), app.restored])
7681
.then(([settings]) => {
82+
settings.changed.connect(onSettingsUpdated);
83+
onSettingsUpdated(settings);
7784
const defaultRepo = settings.get('defaultRepo').composite as string | null;
7885
if (defaultRepo) {
7986
browser.model.restored.then( () => {

0 commit comments

Comments
 (0)