Skip to content

Commit

Permalink
Cherry-pick 274872@main (afa81e7). rdar://123106227
Browse files Browse the repository at this point in the history
    [pre-push] Make version regex more permissive
    https://bugs.webkit.org/show_bug.cgi?id=269599
    rdar://123106227

    Reviewed by Dewei Zhu.

    There exist versions of the pre-push hook which relies on linters to format
    Python code slightly different than WebKit's current style. Our version regex
    should be permissive enough to read such files.

    * Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/install_hooks.py:
    (InstallHooks): Make version regex more permissive.
    * Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/install_hooks_unittest.py:
    (TestInstallHooks.test_version_re):

    Canonical link: https://commits.webkit.org/274872@main

Canonical link: https://commits.webkit.org/272448.575@safari-7618-branch
  • Loading branch information
JonWBedard committed Feb 19, 2024
1 parent ea4b0a7 commit 9378b40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InstallHooks(Command):
help = 'Re-install all hooks from this repository into this checkout'

REMOTE_RE = re.compile(r'(?P<protcol>[^@:]+://)?(?P<user>[^:@]+@)?(?P<host>[^:/@]+)(/|:)(?P<path>[^\.]+[^\./])(\.git)?/?')
VERSION_RE = re.compile(r'^VERSION\s+=\s+\'(?P<number>\d+(\.\d+)*)\'$')
VERSION_RE = re.compile(r'^VERSION\s*=\s*[\'"](?P<number>\d+(\.\d+)*)[\'"]$')
MODES = ('default', 'publish', 'no-radar')

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def test_security_levels(self):
'example.org:project/project-security': 1,
}, program.InstallHooks._security_levels(local.Git(self.path)))

def test_version_re(self):
self.assertEqual(program.InstallHooks.VERSION_RE.match("VERSION = '1.2.3'").group('number'), '1.2.3')
self.assertEqual(program.InstallHooks.VERSION_RE.match("VERSION='1.2.3'").group('number'), '1.2.3')
self.assertEqual(program.InstallHooks.VERSION_RE.match('VERSION = "1.2.3"').group('number'), '1.2.3')

self.assertEqual(program.InstallHooks.VERSION_RE.match('import os'), None)

def test_install_hook(self):
with OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path, remote='git@example.org:project/project'), mocks.local.Svn():
self.write_hook(os.path.join(self.path, 'hooks', 'pre-commit'))
Expand Down

0 comments on commit 9378b40

Please sign in to comment.