Skip to content

Commit 18f6005

Browse files
committed
making github endpoint configurable
1 parent 03109e4 commit 18f6005

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Unreleased (aka. GitHub master)
2121
This is where each new PR to the project should add a summary of its changes,
2222
which makes it much easier to fill in each release's changelog :)
2323

24+
- `gist_it` Making github endpoint configurable to support publishing gists to Github Enterprise
2425

2526
0.5.0
2627
-----

src/jupyter_contrib_nbextensions/nbextensions/gist_it/gist_it.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ Link: readme.md
77
Icon: icon.png
88
Parameters:
99
- name: gist_it_personal_access_token
10-
description: (optional) Github personal access token.
10+
description: Github personal access token. To write gists on a user's behalf, you need a token with the <a href="https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/">gist OAuth scope</a>.
1111
input_type: text
1212
- name: gist_it_default_to_public
1313
description: Gists default to public. If using a personal access token, gists will default to private. Set this to have them default to being public instead.
1414
input_type: checkbox
15+
- name: github_endpoint
16+
description: Github endpoint. Defaults to 'github.com'. Change this to publish to your enterprise github endpoint.
17+
input_type: text
18+
default: 'github.com'

src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define([
3939
var params = {
4040
gist_it_default_to_public: false,
4141
gist_it_personal_access_token: '',
42+
github_endpoint: 'github.com'
4243
};
4344

4445
var initialize = function () {
@@ -170,8 +171,10 @@ define([
170171
.addClass('fa-circle-o-notch fa-spin');
171172
// List commits as a way of checking whether the gist exists.
172173
// Listing commits appears to give the most concise response.
174+
var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
175+
173176
$.ajax({
174-
url: 'https://api.github.com/gists/' + id + '/commits',
177+
url: 'https://api.'+ github_endpoint +'/gists/' + id + '/commits',
175178
dataType: 'json',
176179
beforeSend: add_auth_token,
177180
error: function(jqXHR, textStatus, errorThrown) {
@@ -190,7 +193,7 @@ define([
190193
help_block_html += '<p>' +
191194
'<i class="fa fa-pencil-square"></i>' +
192195
' gist ' +
193-
'<a href="https://gist.github.com/' + id +
196+
'<a href="https://'+ github_endpoint + '/gist/' + id +
194197
'" target="_blank">' + id + '</a> will be updated' +
195198
' (' + jqXHR.responseJSON.length +
196199
' revision' + (single ? '' : 's') +
@@ -440,9 +443,10 @@ define([
440443
var id = params.gist_it_personal_access_token !== '' ? id_input.val() : '';
441444
var method = id ? 'PATCH' : 'POST';
442445

446+
var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
443447
// Create/edit the Gist
444448
$.ajax({
445-
url: 'https://api.github.com/gists' + (id ? '/' + id : ''),
449+
url: 'https://api.'+ github_endpoint +'/gists' + (id ? '/' + id : ''),
446450
type: method,
447451
dataType: 'json',
448452
data: JSON.stringify(data),

0 commit comments

Comments
 (0)