Title: [293784] trunk/Tools
Revision
293784
Author
jbed...@apple.com
Date
2022-05-04 13:20:24 -0700 (Wed, 04 May 2022)

Log Message

[git-webkit] Populate commit message with bug details
https://bugs.webkit.org/show_bug.cgi?id=240022
<rdar://problem/92674438>

Reviewed by Dewei Zhu.

* Tools/Scripts/hooks/prepare-commit-msg: Pull title and bugs from environment variables.
* Tools/Scripts/libraries/webkitcorepy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py:
(PopenBase.__init__): Support environment variables.
(PopenBase.poll): Ditto.
(Popen.__init__): Ditto.
* Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/subprocess.py:
(Subprocess.CommandRoute.__init__): Support environment variables.
(Subprocess.CommandRoute.matches): Ditto
(Subprocess.CommandRoute.__call__): Ditto.
* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py: Pull title and bugs from
environment variables.
(Branch.main): Pass bug title and URLs to caller via args.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.create_commit): Pass title and bug urls to `git commit`.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (293783 => 293784)


--- trunk/Tools/ChangeLog	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/ChangeLog	2022-05-04 20:20:24 UTC (rev 293784)
@@ -1,3 +1,32 @@
+2022-05-04  Jonathan Bedard  <jbed...@apple.com>
+
+        [git-webkit] Populate commit message with bug details
+        https://bugs.webkit.org/show_bug.cgi?id=240022
+        <rdar://problem/92674438>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/hooks/prepare-commit-msg: Pull title and bugs from environment variables.
+        * Scripts/libraries/webkitcorepy/setup.py: Bump version.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py:
+        (PopenBase.__init__): Support environment variables.
+        (PopenBase.poll): Ditto.
+        (Popen.__init__): Ditto.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/mocks/subprocess.py:
+        (Subprocess.CommandRoute.__init__): Support environment variables.
+        (Subprocess.CommandRoute.matches): Ditto
+        (Subprocess.CommandRoute.__call__): Ditto.
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py: Pull title and bugs from
+        environment variables.
+        (Branch.main): Pass bug title and URLs to caller via args.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
+        (PullRequest.create_commit): Pass title and bug urls to `git commit`.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
+
 2022-05-03  Robert Jenner  <jen...@apple.com>
 
         REGRESSION(r287574-r287580): [ iOS ] 3 TestWebKitAPI.WebKitLegacy.* tests are constantly crashing (ScrollingDoesNotPauseMedia, PreemptVideoFullscreen, AudioSessionCategoryIOS)

Modified: trunk/Tools/Scripts/hooks/prepare-commit-msg (293783 => 293784)


--- trunk/Tools/Scripts/hooks/prepare-commit-msg	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/hooks/prepare-commit-msg	2022-05-04 20:20:24 UTC (rev 293784)
@@ -58,13 +58,17 @@
                 dirname = line.split(':')[0]
                 continue
 
-        return '''Need a short description (OOPS!).
-Need the bug URL (OOPS!).
+        return '''{title}
+{bugs}
 
 Reviewed by NOBODY (OOPS!).
 
-{}
-'''.format('\n'.join(commit_message))
+{content}
+'''.format(
+        title=os.environ.get('COMMIT_MESSAGE_TITLE', '') or 'Need a short description (OOPS!).',
+        bugs=os.environ.get('COMMIT_MESSAGE_BUG', '') or 'Need the bug URL (OOPS!).',
+        content='\n'.join(commit_message),
+    )
 
     except subprocess.CalledProcessError:
         return ''

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/setup.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitcorepy',
-    version='0.13.5',
+    version='0.13.6',
     description='Library containing various Python support classes and functions.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -44,7 +44,7 @@
 from webkitcorepy.editor import Editor
 from webkitcorepy.file_lock import FileLock
 
-version = Version(0, 13, 5)
+version = Version(0, 13, 6)
 
 from webkitcorepy.autoinstall import Package, AutoInstall
 if sys.version_info > (3, 0):

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
+# Copyright (C) 2020-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -43,7 +43,7 @@
     SIGTERM = getattr(signal, 'SIGTERM', 1)
     SIGKILL = getattr(signal, 'SIGKILL', 2)
 
-    def __init__(self, args, bufsize=None, cwd=None, stdin=None, stdout=None, stderr=None):
+    def __init__(self, args, bufsize=None, cwd=None, env=None, stdin=None, stdout=None, stderr=None):
         self._completion = None
         self._communication_started = False
         if bufsize is None:
@@ -53,6 +53,7 @@
 
         self._args = args
         self._cwd = cwd
+        self._env = env or dict()
 
         self.returncode = None
 
@@ -80,7 +81,7 @@
     def poll(self):
         if not self._completion:
             self.stdin.seek(0)
-            self._completion = Subprocess.completion_for(*self._args, cwd=self._cwd, input=self.stdin.read())
+            self._completion = Subprocess.completion_for(*self._args, cwd=self._cwd, env=self._env, input=self.stdin.read())
 
             (self.stdout or sys.stdout).write(
                 string_utils.decode(self._completion.stdout, target_type=self._stdout_type))
@@ -126,7 +127,7 @@
                      restore_signals=True, start_new_session=False,
                      pass_fds=(), encoding=None, errors=None, text=None):
 
-            super(Popen, self).__init__(args, bufsize=bufsize, cwd=cwd, stdin=stdin, stdout=stdout, stderr=stderr)
+            super(Popen, self).__init__(args, bufsize=bufsize, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr)
 
             if pass_fds and not close_fds:
                 log.warn("pass_fds overriding close_fds.")
@@ -204,7 +205,7 @@
                      shell=False, cwd=None, env=None, universal_newlines=None,
                      startupinfo=None, creationflags=0):
 
-            super(Popen, self).__init__(args, bufsize=bufsize, cwd=cwd, stdin=stdin, stdout=stdout, stderr=stderr)
+            super(Popen, self).__init__(args, bufsize=bufsize, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr)
 
             for index in range(len(args)):
                 if not isinstance(args[index], (str, unicode)):

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/subprocess.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/subprocess.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/subprocess.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2020-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -69,6 +69,7 @@
             completion = kwargs.pop('completion', ProcessCompletion())
             cwd = kwargs.pop('cwd', None)
             input = kwargs.pop('input', None)
+            env = kwargs.pop('env', None)
             generator = kwargs.pop('generator', None)
             if kwargs.keys():
                 raise TypeError('__init__() got an unexpected keyword argument {}'.format(kwargs.keys()[0]))
@@ -83,10 +84,12 @@
             self.generator = generator or (lambda *args, **kwargs: completion)
             self.cwd = cwd
             self.input = string_utils.encode(input) if input else None
+            self.env = env
 
         def matches(self, *args, **kwargs):
             cwd = kwargs.pop('cwd', None)
             input = kwargs.pop('input', None)
+            env = kwargs.pop('env', None)
             if kwargs.keys():
                 raise TypeError('matches() got an unexpected keyword argument {}'.format(kwargs.keys()[0]))
 
@@ -109,14 +112,17 @@
                 return False
             if self.input is not None and input != self.input:
                 return False
+            if self.env is not None and env != self.env:
+                return False
             return True
 
         def __call__(self, *args, **kwargs):
             cwd = kwargs.pop('cwd', None)
             input = kwargs.pop('input', None)
+            env = kwargs.pop('env', dict())
             if kwargs.keys():
                 raise TypeError('__call__() got an unexpected keyword argument {}'.format(kwargs.keys()[0]))
-            return self.generator(*args, cwd=cwd, input=input)
+            return self.generator(*args, cwd=cwd, input=input, env=env)
 
         @classmethod
         def compare(cls, a, b):

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.12.2',
+    version='4.12.3',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 12, 2)
+version = Version(4, 12, 3)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -480,11 +480,11 @@
             ), mocks.Subprocess.Route(
                 self.executable, 'commit', '--date=now',
                 cwd=self.path,
-                generator=lambda *args, **kwargs: self.commit(amend=False),
+                generator=lambda *args, **kwargs: self.commit(amend=False, env=kwargs.get('env', dict())),
             ), mocks.Subprocess.Route(
                 self.executable, 'commit', '--date=now', '--amend',
                 cwd=self.path,
-                generator=lambda *args, **kwargs: self.commit(amend=True),
+                generator=lambda *args, **kwargs: self.commit(amend=True, env=kwargs.get('env', dict())),
             ), mocks.Subprocess.Route(
                 self.executable, 'revert', '--no-commit', re.compile(r'.+'),
                 cwd=self.path,
@@ -902,7 +902,8 @@
 
         return mocks.ProcessCompletion(returncode=0)
 
-    def commit(self, amend=False):
+    def commit(self, amend=False, env=None):
+        env = env or dict()
         if not self.head:
             return mocks.ProcessCompletion(returncode=1, stdout='Allowed in git, but disallowed by reasonable workflows')
         if not self.staged and not amend:
@@ -918,8 +919,9 @@
             self.commits[self.branch].append(self.head)
 
         self.head.author = Contributor(self.config()['user.name'], [self.config()['user.email']])
-        self.head.message = '[Testing] {} commits\nReviewed by Jonathan Bedard\n\n * {}\n'.format(
-            'Amending' if amend else 'Creating',
+        self.head.message = '{}{}\nReviewed by Jonathan Bedard\n\n * {}\n'.format(
+            env.get('COMMIT_MESSAGE_TITLE', '') or '[Testing] {} commits'.format('Amending' if amend else 'Creating'),
+            ('\n' + env.get('COMMIT_MESSAGE_BUG', '')) if env.get('COMMIT_MESSAGE_BUG', '') else '',
             '\n * '.join(self.staged.keys()),
         )
         self.head.hash = hashlib.sha256(string_utils.encode(self.head.message)).hexdigest()[:40]

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -111,6 +111,16 @@
             elif issue:
                 args.issue = str(issue.id)
 
+        if issue:
+            args._title = issue.title
+            args._bug_urls = [issue.link]
+            types = [type(issue.tracker)]
+            for related in issue.references:
+                if type(related.tracker) in types:
+                    continue
+                args._bug_urls.append(related.link)
+                types.append(type(related.tracker))
+
         args.issue = cls.normalize_branch_name(args.issue)
 
         if run([repository.executable(), 'check-ref-format', args.issue], capture_output=True).returncode:

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -108,6 +108,10 @@
             log.info('Using committed changes...')
             return 0
 
+        bug_urls = getattr(args, '_bug_urls', None) or ''
+        if isinstance(bug_urls, (list, tuple)):
+            bug_urls = '\n'.join(bug_urls)
+
         # Otherwise, we need to create a commit
         will_amend = has_commit and args.technique == 'overwrite'
         if not modified:
@@ -114,7 +118,14 @@
             sys.stderr.write('No modified files\n')
             return 1
         log.info('Amending commit...' if will_amend else 'Creating commit...')
-        if run([repository.executable(), 'commit', '--date=now'] + (['--amend'] if will_amend else []), cwd=repository.root_path).returncode:
+        if run(
+            [repository.executable(), 'commit', '--date=now'] + (['--amend'] if will_amend else []),
+            cwd=repository.root_path,
+            env=dict(
+                COMMIT_MESSAGE_TITLE=getattr(args, '_title', None) or '',
+                COMMIT_MESSAGE_BUG=bug_urls,
+            ),
+        ).returncode:
             sys.stderr.write('Failed to generate commit\n')
             return 1
 

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py (293783 => 293784)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-05-04 19:20:58 UTC (rev 293783)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-05-04 20:20:24 UTC (rev 293784)
@@ -612,6 +612,65 @@
             ],
         )
 
+    def test_github_branch_bugzilla(self):
+        self.maxDiff = None
+        with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub(projects=bmocks.PROJECTS) as remote, bmocks.Bugzilla(
+            self.BUGZILLA.split('://')[-1],
+            projects=bmocks.PROJECTS, issues=bmocks.ISSUES,
+            environment=Environment(
+                BUGS_EXAMPLE_COM_USERNAME='tcontribu...@example.com',
+                BUGS_EXAMPLE_COM_PASSWORD='password',
+            )), patch(
+                'webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)],
+        ), mocks.local.Git(
+            self.path, remote='https://{}'.format(remote.remote),
+            remotes=dict(fork='https://{}/Contributor/WebKit'.format(remote.hosts[0])),
+        ) as repo, mocks.local.Svn():
+
+            repo.staged['added.txt'] = 'added'
+            self.assertEqual(0, program.main(
+                args=('pull-request', '-i', 'https://bugs.example.com/show_bug.cgi?id=1', '-v', '--no-history'),
+                path=self.path,
+            ))
+
+            self.assertEqual(
+                Tracker.instance().issue(1).comments[-1].content,
+                'Pull request: https://github.example.com/WebKit/WebKit/pull/1',
+            )
+            gh_issue = github.Tracker('https://github.example.com/WebKit/WebKit').issue(1)
+            self.assertEqual(gh_issue.project, 'WebKit')
+            self.assertEqual(gh_issue.component, 'Text')
+            self.assertEqual(gh_issue.version, 'Other')
+
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            "Created the local development branch 'eng/Example-issue-1'\n"
+            "Created 'PR 1 | Example issue 1'!\n"
+            "Posted pull request link to https://bugs.example.com/show_bug.cgi?id=1\n"
+            "https://github.example.com/WebKit/WebKit/pull/1\n",
+        )
+        self.assertEqual(captured.stderr.getvalue(), '')
+        log = captured.root.log.getvalue().splitlines()
+        self.assertEqual(
+            [line for line in log if 'Mock process' not in line], [
+                "Creating the local development branch 'eng/Example-issue-1'...",
+                '    Found 1 commit...',
+                'Creating commit...',
+                "Rebasing 'eng/Example-issue-1' on 'main'...",
+                "Rebased 'eng/Example-issue-1' on 'main!'",
+                "    Found 1 commit...",
+                'Running pre-PR checks...',
+                'No pre-PR checks to run',
+                "Pushing 'eng/Example-issue-1' to 'fork'...",
+                "Syncing 'main' to remote 'fork'",
+                "Creating pull-request for 'eng/Example-issue-1'...",
+                'Checking issue assignee...',
+                'Checking for pull request link in associated issue...',
+                'Syncing PR labels with issue component...',
+                'Synced PR labels with issue component!',
+            ],
+        )
+
     def test_github_reopen_bugzilla(self):
         with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, bmocks.Bugzilla(
             self.BUGZILLA.split('://')[-1],
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to