mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Update regex for VCS permalinks
This commit is contained in:
parent
bf8369c862
commit
321e2602eb
2 changed files with 17 additions and 5 deletions
|
|
@ -8,7 +8,7 @@ import sys
|
||||||
|
|
||||||
|
|
||||||
GITHUB_NON_PERMALINK = re.compile(
|
GITHUB_NON_PERMALINK = re.compile(
|
||||||
b'https://github.com/[^/]+/[^/]+/blob/master/[^# ]+#L\d+',
|
b'https?://(www\.)?github.com/[^/]+/[^/]+/blob/master/[^# ]+#',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from pre_commit_hooks.check_vcs_permalinks import main
|
from pre_commit_hooks.check_vcs_permalinks import main
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,17 +22,27 @@ def test_passing(tmpdir):
|
||||||
assert not main((f.strpath,))
|
assert not main((f.strpath,))
|
||||||
|
|
||||||
|
|
||||||
def test_failing(tmpdir, capsys):
|
@pytest.mark.parametrize(
|
||||||
|
'contents',
|
||||||
|
(
|
||||||
|
'http://github.com/asottile/test/blob/master/foo#L1',
|
||||||
|
'http://www.github.com/asottile/test/blob/master/foo#L1',
|
||||||
|
'https://github.com/asottile/test/blob/master/foo#L1',
|
||||||
|
'https://www.github.com/asottile/test/blob/master/foo#L1',
|
||||||
|
'https://www.github.com/asottile/test/blob/master/foo#my-anchor',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_failing(contents, tmpdir, capsys):
|
||||||
with tmpdir.as_cwd():
|
with tmpdir.as_cwd():
|
||||||
tmpdir.join('f.txt').write_binary(
|
tmpdir.join('f.txt').write_binary(
|
||||||
b'https://github.com/asottile/test/blob/master/foo#L1\n',
|
'{}\n'.format(contents).encode('utf-8'),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert main(('f.txt',))
|
assert main(('f.txt',))
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert out == (
|
assert out == (
|
||||||
'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
|
'f.txt:1:{}\n'
|
||||||
'\n'
|
'\n'
|
||||||
'Non-permanent github link detected.\n'
|
'Non-permanent github link detected.\n'
|
||||||
'On any page on github press [y] to load a permalink.\n'
|
'On any page on github press [y] to load a permalink.\n'.format(contents)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue