Skip to content

Commit 142d690

Browse files
committed
more fixes
1 parent aa08341 commit 142d690

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
- name: install
3333
run: |
3434
python3 -m pip install -r requirements.in -r requirements-dev.txt
35+
- name: install mypy
36+
run: |
37+
python3 -m pip install mypy types-pycurl types-requests types-Markdown
3538
3639
- name: pip freeze
3740
run: |

nbviewer/providers/github/handlers.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,15 @@ async def get(self, user, repo, ref, path):
233233
# Account for possibility that GitHub API redirects us to get more accurate breadcrumbs
234234
# See: https://github.com/jupyter/nbviewer/issues/324
235235
example_file_url = contents[0]["html_url"]
236-
match_group = re.match(
237-
r"^" + self.github_url + r"(?P<user>[^\/]+)/(?P<repo>[^\/]+)/.*",
238-
example_file_url,
236+
237+
if not example_file_url.startswith(self.github_url):
238+
raise ValueError("Url will never match it does not start with same domain.")
239+
ghu = (
240+
self.github_url if self.github_url.endswith("/") else self.github_url + "/"
239241
)
240242

241-
if match_group is None:
242-
raise ValueError(
243-
f"Could not extract user/repo fromexample_file_url={example_file_url}"
244-
)
245-
user, repo = match_group.group("user", "repo")
243+
example_file_path = example_file_url[len(ghu) :]
244+
user, repo, *_more = example_file_path.split("/")
246245

247246
base_url = "/github/{user}/{repo}/tree/{ref}".format(
248247
user=user, repo=repo, ref=ref

nbviewer/providers/github/tests/test_github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_github_tree_redirect(self):
140140
self.assertIn("global-exclude", r.text)
141141

142142
@skip_unless_github_auth
143-
def test_github_blob_redirect(self):
143+
def test_github_blob_redirect_II(self):
144144
url = self.url("github/ipython/ipython/blob/rel-2.0.0/IPython")
145145
r = requests.get(url)
146146
self.assertEqual(r.status_code, 200)

nbviewer/tests/test_json.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from unittest import TestCase
44

55
from jsonschema import validate
6+
from typing import Optional
67

78

89
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
910

1011

1112
class JSONTestCase(TestCase):
12-
json: str
13-
schema: str
13+
json: Optional[str] = None
14+
schema: Optional[str] = None
1415

1516
def test_json(self):
1617
if not self.json:

0 commit comments

Comments
 (0)