Skip to content

Commit b767c69

Browse files
authored
Merge pull request #1448 from mskimm/enterprise_endpoint
fix endpoint for Github Enterprise
2 parents 8f006c0 + f54d306 commit b767c69

File tree

1 file changed

+18
-5
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/gist_it

1 file changed

+18
-5
lines changed

src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ define([
140140
alert.slideDown('fast');
141141
}
142142

143+
function get_github_endpoint() {
144+
return params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
145+
}
146+
147+
function get_api_endpoint() {
148+
const github_endpoint = get_github_endpoint();
149+
if (github_endpoint === 'github.com') {
150+
return 'https://api.'+ github_endpoint;
151+
} else {
152+
// Github Enterprise
153+
// https://developer.github.com/enterprise/2.18/v3/enterprise-admin/#endpoint-urls
154+
return 'https://' + github_endpoint + '/api/v3'
155+
}
156+
}
157+
143158
function gist_id_updated_callback(gist_editor) {
144159
if (gist_editor === undefined) gist_editor = $('#gist_editor');
145160

@@ -171,10 +186,9 @@ define([
171186
.addClass('fa-circle-o-notch fa-spin');
172187
// List commits as a way of checking whether the gist exists.
173188
// Listing commits appears to give the most concise response.
174-
var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
175189

176190
$.ajax({
177-
url: 'https://api.'+ github_endpoint +'/gists/' + id + '/commits',
191+
url: get_api_endpoint() +'/gists/' + id + '/commits',
178192
dataType: 'json',
179193
beforeSend: add_auth_token,
180194
error: function(jqXHR, textStatus, errorThrown) {
@@ -193,7 +207,7 @@ define([
193207
help_block_html += '<p>' +
194208
'<i class="fa fa-pencil-square"></i>' +
195209
' gist ' +
196-
'<a href="https://'+ github_endpoint + '/gist/' + id +
210+
'<a href="https://'+ get_github_endpoint() + '/gist/' + id +
197211
'" target="_blank">' + id + '</a> will be updated' +
198212
' (' + jqXHR.responseJSON.length +
199213
' revision' + (single ? '' : 's') +
@@ -443,10 +457,9 @@ define([
443457
var id = params.gist_it_personal_access_token !== '' ? id_input.val() : '';
444458
var method = id ? 'PATCH' : 'POST';
445459

446-
var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
447460
// Create/edit the Gist
448461
$.ajax({
449-
url: 'https://api.'+ github_endpoint +'/gists' + (id ? '/' + id : ''),
462+
url: get_api_endpoint() +'/gists' + (id ? '/' + id : ''),
450463
type: method,
451464
dataType: 'json',
452465
data: JSON.stringify(data),

0 commit comments

Comments
 (0)