Skip to content

Commit 2993597

Browse files
committed
switch master to default branch
1 parent cf693bd commit 2993597

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

nbviewer/providers/github/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ def get_gists(self, user, **kwargs):
135135
path = u"users/{user}/gists".format(user=user)
136136
return self.github_api_request(path, **kwargs)
137137

138+
def get_repo(self, user, repo, **kwargs):
139+
"""List a repo's branches"""
140+
path = u"repos/{user}/{repo}".format(user=user, repo=repo)
141+
return self.github_api_request(path, **kwargs)
142+
138143
def get_tree(self, user, repo, path, ref="master", recursive=False, **kwargs):
139144
"""Get a git tree"""
140145
# only need a recursive fetch if it's not in the top-level dir

nbviewer/providers/github/handlers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ async def get(self, user):
141141
await self.cache_and_finish(html)
142142

143143

144-
class GitHubRepoHandler(BaseHandler):
144+
class GitHubRepoHandler(GithubClientMixin, BaseHandler):
145145
"""redirect /github/user/repo to .../tree/master"""
146146

147-
def get(self, user, repo):
147+
async def get(self, user, repo):
148+
response = await self.github_client.get_repo(user, repo)
149+
default_branch = json.loads(response_text(response))['default_branch']
150+
148151
new_url = self.from_base(
149-
"/", self.format_prefix, "github", user, repo, "tree", "master"
152+
"/", self.format_prefix, "github", user, repo, "tree", default_branch
150153
)
151154
self.log.info("Redirecting %s to %s", self.request.uri, new_url)
152155
self.redirect(new_url)

0 commit comments

Comments
 (0)