Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Unreleased (aka. GitHub master)
This is where each new PR to the project should add a summary of its changes,
which makes it much easier to fill in each release's changelog :)

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

0.5.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ Link: readme.md
Icon: icon.png
Parameters:
- name: gist_it_personal_access_token
description: (optional) Github personal access token.
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>.
input_type: text
- name: gist_it_default_to_public
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.
input_type: checkbox
- name: github_endpoint
description: Github endpoint. Defaults to 'github.com'. Change this to publish to your enterprise github endpoint.
input_type: text
default: 'github.com'
10 changes: 7 additions & 3 deletions src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define([
var params = {
gist_it_default_to_public: false,
gist_it_personal_access_token: '',
github_endpoint: 'github.com'
};

var initialize = function () {
Expand Down Expand Up @@ -170,8 +171,10 @@ define([
.addClass('fa-circle-o-notch fa-spin');
// List commits as a way of checking whether the gist exists.
// Listing commits appears to give the most concise response.
var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';

$.ajax({
url: 'https://api.github.com/gists/' + id + '/commits',
url: 'https://api.'+ github_endpoint +'/gists/' + id + '/commits',
dataType: 'json',
beforeSend: add_auth_token,
error: function(jqXHR, textStatus, errorThrown) {
Expand All @@ -190,7 +193,7 @@ define([
help_block_html += '<p>' +
'<i class="fa fa-pencil-square"></i>' +
' gist ' +
'<a href="https://gist.github.com/' + id +
'<a href="https://'+ github_endpoint + '/gist/' + id +
'" target="_blank">' + id + '</a> will be updated' +
' (' + jqXHR.responseJSON.length +
' revision' + (single ? '' : 's') +
Expand Down Expand Up @@ -440,9 +443,10 @@ define([
var id = params.gist_it_personal_access_token !== '' ? id_input.val() : '';
var method = id ? 'PATCH' : 'POST';

var github_endpoint = params.github_endpoint !== '' ? params.github_endpoint : 'github.com';
// Create/edit the Gist
$.ajax({
url: 'https://api.github.com/gists' + (id ? '/' + id : ''),
url: 'https://api.'+ github_endpoint +'/gists' + (id ? '/' + id : ''),
type: method,
dataType: 'json',
data: JSON.stringify(data),
Expand Down