@@ -140,6 +140,21 @@ define([
140
140
alert . slideDown ( 'fast' ) ;
141
141
}
142
142
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
+
143
158
function gist_id_updated_callback ( gist_editor ) {
144
159
if ( gist_editor === undefined ) gist_editor = $ ( '#gist_editor' ) ;
145
160
@@ -171,10 +186,9 @@ define([
171
186
. addClass ( 'fa-circle-o-notch fa-spin' ) ;
172
187
// List commits as a way of checking whether the gist exists.
173
188
// Listing commits appears to give the most concise response.
174
- var github_endpoint = params . github_endpoint !== '' ? params . github_endpoint : 'github.com' ;
175
189
176
190
$ . ajax ( {
177
- url : 'https://api.' + github_endpoint + '/gists/' + id + '/commits' ,
191
+ url : get_api_endpoint ( ) + '/gists/' + id + '/commits' ,
178
192
dataType : 'json' ,
179
193
beforeSend : add_auth_token ,
180
194
error : function ( jqXHR , textStatus , errorThrown ) {
@@ -193,7 +207,7 @@ define([
193
207
help_block_html += '<p>' +
194
208
'<i class="fa fa-pencil-square"></i>' +
195
209
' gist ' +
196
- '<a href="https://' + github_endpoint + '/gist/' + id +
210
+ '<a href="https://' + get_github_endpoint ( ) + '/gist/' + id +
197
211
'" target="_blank">' + id + '</a> will be updated' +
198
212
' (' + jqXHR . responseJSON . length +
199
213
' revision' + ( single ? '' : 's' ) +
@@ -443,10 +457,9 @@ define([
443
457
var id = params . gist_it_personal_access_token !== '' ? id_input . val ( ) : '' ;
444
458
var method = id ? 'PATCH' : 'POST' ;
445
459
446
- var github_endpoint = params . github_endpoint !== '' ? params . github_endpoint : 'github.com' ;
447
460
// Create/edit the Gist
448
461
$ . ajax ( {
449
- url : 'https://api.' + github_endpoint + '/gists' + ( id ? '/' + id : '' ) ,
462
+ url : get_api_endpoint ( ) + '/gists' + ( id ? '/' + id : '' ) ,
450
463
type : method ,
451
464
dataType : 'json' ,
452
465
data : JSON . stringify ( data ) ,
0 commit comments