1 parent 4195f4d commit 4729918Copy full SHA for 4729918
2 files changed
pre_commit_hooks/check_vcs_permalinks.py
@@ -8,7 +8,10 @@
8
9
10
def _get_pattern(domain: str) -> Pattern[bytes]:
11
- regex = rf'https://{domain}/[^/ ]+/[^/ ]+/blob/master/[^# ]+#L\d+'
+ regex = (
12
+ rf'https://{domain}/[^/ ]+/[^/ ]+/blob/'
13
+ r'(?![a-fA-F0-9]{4,64}/)([^/. ]+)/[^# ]+#L\d+'
14
+ )
15
return re.compile(regex.encode())
16
17
tests/check_vcs_permalinks_test.py
@@ -11,6 +11,8 @@ def test_passing(tmpdir):
f.write_binary(
# permalinks are ok
b'https://github.com/asottile/test/blob/649e6/foo%20bar#L1\n'
+ # tags are ok
+ b'https://github.com/asottile/test/blob/1.0.0/foo%20bar#L1\n'
# links to files but not line numbers are ok
b'https://github.com/asottile/test/blob/master/foo%20bar\n'
18
# regression test for overly-greedy regex
@@ -23,14 +25,16 @@ def test_failing(tmpdir, capsys):
23
25
with tmpdir.as_cwd():
24
26
tmpdir.join('f.txt').write_binary(
27
b'https://github.com/asottile/test/blob/master/foo#L1\n'
- b'https://example.com/asottile/test/blob/master/foo#L1\n',
28
+ b'https://example.com/asottile/test/blob/master/foo#L1\n'
29
+ b'https://example.com/asottile/test/blob/main/foo#L1\n',
30
)
31
32
assert main(('f.txt', '--additional-github-domain', 'example.com'))
33
out, _ = capsys.readouterr()
34
assert out == (
35
'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
36
'f.txt:2:https://example.com/asottile/test/blob/master/foo#L1\n'
37
+ 'f.txt:3:https://example.com/asottile/test/blob/main/foo#L1\n'
38
'\n'
39
'Non-permanent github link detected.\n'
40
'On any page on github press [y] to load a permalink.\n'
0 commit comments