From 71b4b3953d3ce1ab416b267bd78352e786f3ce7c Mon Sep 17 00:00:00 2001 From: fireundubh Date: Sat, 11 Jan 2020 02:51:17 -0800 Subject: [PATCH] Fixed issue where only master branch remotes were supported --- pyro/PapyrusProject.py | 2 +- pyro/Remotes.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pyro/PapyrusProject.py b/pyro/PapyrusProject.py index c11ee0bc..25fd606f 100644 --- a/pyro/PapyrusProject.py +++ b/pyro/PapyrusProject.py @@ -503,7 +503,7 @@ def _get_remote_path(self, node: etree.ElementBase) -> str: url_path = os.sep.join(url_path_parts) elif parsed_url.netloc == 'github.com': url_path_parts = parsed_url.path.split('/')[1:] - url_path_parts.pop(3) # pop 'master' + url_path_parts.pop(3) # pop 'master' (or any other branch) url_path_parts.pop(2) # pop 'tree' url_path = os.sep.join(url_path_parts) else: diff --git a/pyro/Remotes.py b/pyro/Remotes.py index ccda9ac1..58993330 100644 --- a/pyro/Remotes.py +++ b/pyro/Remotes.py @@ -47,10 +47,16 @@ def get_contents(self, url: str, output_path: str) -> Generator: if parsed_url.netloc == 'api.github.com': request_url = url _, owner, repo = url_path.split('/')[:3] - else: - url_path = url_path.replace('tree/master', 'contents') + elif parsed_url.netloc == 'github.com': + url_path_parts = parsed_url.path.split('/')[1:] + url_path_parts.pop(3) # pop 'master' (or any other branch) + url_path_parts.pop(2) # pop 'tree' + url_path_parts.insert(2, 'contents') + url_path = '/'.join(url_path_parts) request_url = f'https://api.github.com/repos/{url_path}' - owner, repo = url_path.split('/')[:2] + owner, repo = url_path_parts[0], url_path_parts[1] + else: + raise NotImplementedError request = Request(request_url) request.add_header('Authorization', f'token {self.access_token}')