|
1 | 1 | # Copyright (c) Jupyter Development Team.
|
2 | 2 | # Distributed under the terms of the Modified BSD License.
|
3 | 3 |
|
| 4 | +import os |
4 | 5 | import json
|
5 | 6 |
|
6 | 7 | from tornado import web, gen
|
|
17 | 18 | clean_filename,
|
18 | 19 | quote,
|
19 | 20 | response_text,
|
| 21 | + url_path_join, |
20 | 22 | )
|
21 | 23 |
|
22 | 24 | from ..github.handlers import GithubClientMixin
|
@@ -96,9 +98,14 @@ def get(self, user, **namespace):
|
96 | 98 | notebooks=notebooks,
|
97 | 99 | description=gist['description'] or '',
|
98 | 100 | ))
|
99 |
| - provider_url = u"https://gist.github.com/{user}".format(user=user) |
| 101 | + if self.github_url == 'https://github.com/': |
| 102 | + gist_base_url = 'https://gist.github.com/' |
| 103 | + else: |
| 104 | + gist_base_url = url_path_join(self.github_url, 'gist/') |
| 105 | + provider_url = url_path_join(gist_base_url, u"{user}".format(user=user)) |
100 | 106 | html = self.render_usergists_template(entries=entries, user=user, provider_url=provider_url,
|
101 | 107 | prev_url=prev_url, next_url=next_url, **namespace
|
| 108 | + |
102 | 109 | )
|
103 | 110 | yield self.cache_and_finish(html)
|
104 | 111 |
|
@@ -155,11 +162,15 @@ def tree_get(self, user, gist_id, gist, files):
|
155 | 162 | e['class'] = 'fa-book'
|
156 | 163 | ipynbs.append(e)
|
157 | 164 | else:
|
158 |
| - provider_url = u"https://gist.github.com/{user}/{gist_id}#file-{clean_name}".format( |
| 165 | + if self.github_url == 'https://github.com/': |
| 166 | + gist_base_url = 'https://gist.github.com/' |
| 167 | + else: |
| 168 | + gist_base_url = url_path_join(self.github_url, 'gist/') |
| 169 | + provider_url = url_path_join(gist_base_url, u"{user}/{gist_id}#file-{clean_name}".format( |
159 | 170 | user=user,
|
160 | 171 | gist_id=gist_id,
|
161 | 172 | clean_name=clean_filename(file['filename']),
|
162 |
| - ) |
| 173 | + )) |
163 | 174 | e['url'] = provider_url
|
164 | 175 | e['class'] = 'fa-share'
|
165 | 176 | others.append(e)
|
@@ -305,9 +316,19 @@ def default_handlers(handlers=[], **handler_names):
|
305 | 316 |
|
306 | 317 |
|
307 | 318 | def uri_rewrites(rewrites=[]):
|
308 |
| - return [ |
| 319 | + gist_rewrites = [ |
309 | 320 | (r'^([a-f0-9]+)/?$',
|
310 | 321 | u'/{0}'),
|
311 |
| - ('^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$', |
| 322 | + (r'^https?://gist.github.com/([^\/]+/)?([a-f0-9]+)/?$', |
312 | 323 | u'/{1}'),
|
313 |
| - ] + rewrites |
| 324 | + ] |
| 325 | + # github enterprise |
| 326 | + if os.environ.get('GITHUB_API_URL', '') != '': |
| 327 | + gist_base_url = url_path_join(os.environ.get('GITHUB_API_URL').split('/api/v3')[0], 'gist/') |
| 328 | + gist_rewrites.extend([ |
| 329 | + # Fetching the Gist ID which is embedded in the URL, but with a different base URL |
| 330 | + (r'^' + gist_base_url + r'([^\/]+/)?([a-f0-9]+)/?$', |
| 331 | + u'/{1}'), |
| 332 | + ]) |
| 333 | + |
| 334 | + return gist_rewrites + rewrites |
0 commit comments