Skip to content

Commit 4933ef1

Browse files
authored
Merge pull request #864 from ivan-gomes/ghe-uri-rewrite-patch
Fix repo and user links for GHE
2 parents 8a8fd29 + 4cb335a commit 4933ef1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

nbviewer/providers/github/handlers.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,27 @@ def uri_rewrites(rewrites=[]):
433433
]
434434
# github enterprise
435435
if os.environ.get('GITHUB_API_URL', '') != '':
436-
github_api_url = os.environ.get('GITHUB_API_URL')
436+
github_base_url = os.environ.get('GITHUB_API_URL').split('api/v3')[0]
437437

438438
github_rewrites.extend([
439439
# raw view
440-
(r'^' + github_api_url.split('/api/v3/')[0]
441-
+ '/([^\/]+)/([^\/]+)/raw/([^\/]+)/(.*)',
440+
(r'^' + github_base_url
441+
+ r'([^\/]+)/([^\/]+)/raw/([^\/]+)/(.*)',
442442
u'/github/{0}/{1}/blob/{2}/{3}'),
443443

444444
# trees & blobs
445-
(r'^' + github_api_url.split('/api/v3/')[0]
446-
+ '/([\w\-]+)/([^\/]+)/(blob|tree)/(.*)$',
445+
(r'^' + github_base_url
446+
+ r'([\w\-]+)/([^\/]+)/(blob|tree)/(.*)$',
447447
u'/github/{0}/{1}/{2}/{3}'),
448+
449+
# user/repo
450+
(r'^' + github_base_url
451+
+ r'([\w\-]+)/([^\/]+)/?$',
452+
u'/github/{0}/{1}/tree/master'),
453+
454+
# user
455+
(r'^' + github_base_url
456+
+ r'([\w\-]+)/?$',
457+
u'/github/{0}/'),
448458
])
449459
return rewrites + github_rewrites

0 commit comments

Comments
 (0)