Title: [289983] trunk/Tools
Revision
289983
Author
jbed...@apple.com
Date
2022-02-16 17:10:43 -0800 (Wed, 16 Feb 2022)

Log Message

[git-webkit] Comment and close issue when landing PR
https://bugs.webkit.org/show_bug.cgi?id=236715
<rdar://problem/89031529>

Reviewed by Ryan Haddad.

When we land pull requests, we should make a comment on the associated issue
indicating where the code change is and close that issue.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py:
(Land.main): Comment on and close issue associated with the final commit in
the landed series, shorten displayed hash to 12 characters.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py:
(repository): Allow caller to specify issue URL in commit message, append git-svn
tag if in a git-svn repository.
(TestLand):
(TestLand.test_default):
(TestLand.test_canonicalize):
(TestLand.test_svn):
(TestLand.test_default_with_radar):
(TestLand.test_canonicalize_with_bugzilla):
(TestLand.test_svn_with_bugzilla):

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (289982 => 289983)


--- trunk/Tools/ChangeLog	2022-02-17 00:40:31 UTC (rev 289982)
+++ trunk/Tools/ChangeLog	2022-02-17 01:10:43 UTC (rev 289983)
@@ -1,3 +1,30 @@
+2022-02-16  Jonathan Bedard  <jbed...@apple.com>
+
+        [git-webkit] Comment and close issue when landing PR
+        https://bugs.webkit.org/show_bug.cgi?id=236715
+        <rdar://problem/89031529>
+
+        Reviewed by Ryan Haddad.
+
+        When we land pull requests, we should make a comment on the associated issue
+        indicating where the code change is and close that issue.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py:
+        (Land.main): Comment on and close issue associated with the final commit in
+        the landed series, shorten displayed hash to 12 characters.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py:
+        (repository): Allow caller to specify issue URL in commit message, append git-svn
+        tag if in a git-svn repository.
+        (TestLand):
+        (TestLand.test_default):
+        (TestLand.test_canonicalize):
+        (TestLand.test_svn):
+        (TestLand.test_default_with_radar):
+        (TestLand.test_canonicalize_with_bugzilla):
+        (TestLand.test_svn_with_bugzilla):
+
 2022-02-16  Diego Pino Garcia  <dp...@igalia.com>
 
         [GTK][WPE] Execute API test by name

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (289982 => 289983)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-17 00:40:31 UTC (rev 289982)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-17 01:10:43 UTC (rev 289983)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.2.0',
+    version='4.1.0',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (289982 => 289983)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-17 00:40:31 UTC (rev 289982)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-17 01:10:43 UTC (rev 289983)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 2, 0)
+version = Version(4, 1, 0)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py (289982 => 289983)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py	2022-02-17 00:40:31 UTC (rev 289982)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py	2022-02-17 01:10:43 UTC (rev 289983)
@@ -29,8 +29,9 @@
 from .branch import Branch
 from .pull_request import PullRequest
 from argparse import Namespace
+from webkitbugspy import Tracker
 from webkitcorepy import arguments, run, string_utils, Terminal
-from webkitscmpy import local, log, remote
+from webkitscmpy import Commit, local, log, remote
 
 
 class Land(Command):
@@ -151,6 +152,12 @@
                     sys.stderr.write("Found '(OOPS!)' in commit diff, please resolve before committing\n")
                     return 1
 
+        issue = None
+        for line in commits[0].message.split() if commits[0] and commits[0].message else []:
+            issue = Tracker.from_string(line)
+            if issue:
+                break
+
         target = pull_request.base if pull_request else branch_point.branch
         log.info("Rebasing '{}' from '{}' to '{}'...".format(source_branch, branch_point.branch, target))
         if repository.fetch(branch=target, remote=cls.REMOTE):
@@ -233,13 +240,17 @@
 
         commit = repository.commit(branch=target, include_log=False)
         if identifier_template and commit.identifier:
-            land_message = 'Landed {} ({})!'.format(identifier_template.format(commit).split(': ')[-1], commit.hash)
+            land_message = 'Landed {} ({})!'.format(identifier_template.format(commit).split(': ')[-1], commit.hash[:Commit.HASH_LABEL_SIZE])
         else:
-            land_message = 'Landed {}!'.format(commit.hash)
+            land_message = 'Landed {}!'.format(commit.hash[:Commit.HASH_LABEL_SIZE])
         print(land_message)
 
         if pull_request:
             pull_request.comment(land_message)
+        if issue:
+            if canonical_svn and commit.revision:
+                land_message = land_message.replace(commit.hash[:Commit.HASH_LABEL_SIZE], 'r{}'.format(commit.revision))
+            issue.close(why=land_message)
 
         if args.defaults or Terminal.choose("Delete branch '{}'?".format(source_branch), default='Yes') == 'Yes':
             regex = re.compile(r'^{}-(?P<count>\d+)$'.format(source_branch))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py (289982 => 289983)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py	2022-02-17 00:40:31 UTC (rev 289982)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py	2022-02-17 01:10:43 UTC (rev 289983)
@@ -24,12 +24,14 @@
 import os
 import time
 
+from mock import patch
+from webkitbugspy import Tracker, User, bugzilla, radar, mocks as bmocks
 from webkitcorepy import OutputCapture, testing
-from webkitcorepy.mocks import Terminal as MockTerminal, Time as MockTime
+from webkitcorepy.mocks import Terminal as MockTerminal, Time as MockTime, Environment
 from webkitscmpy import Contributor, Commit, local, program, mocks
 
 
-def repository(path, has_oops=True, remote=None, git_svn=False):
+def repository(path, has_oops=True, remote=None, git_svn=False, issue_url=None):
     branch = 'eng/example'
     result = mocks.local.Git(path, remote=remote, git_svn=git_svn)
     result.commits[branch] = [Commit(
@@ -37,8 +39,13 @@
         identifier='3.1@{}'.format(branch),
         timestamp=int(time.time()) - 60,
         author=Contributor('Tim Committer', ['tcommit...@webkit.org']),
-        message='To Be Committed\n\nReviewed by {}.\n'.format(
+        message='To Be Committed\n{}\nReviewed by {}.\n{}'.format(
+            '{}\n'.format(issue_url) if issue_url else '',
             'NOBODY (OOPS!)' if has_oops else 'Ricky Reviewer',
+            '\ngit-svn-id: https://svn.{}/repository/{}/trunk@10 268f45cc-cd09-0410-ab3c-d52691b4dbfc\n'.format(
+                result.remote.split('@')[-1].split(':')[0],
+                os.path.basename(result.path),
+            ) if git_svn else '',
         ),
     )]
     result.head = result.commits[branch][0]
@@ -47,6 +54,7 @@
 
 class TestLand(testing.PathTestCase):
     basepath = 'mock/repository'
+    BUGZILLA = 'https://bugs.example.com'
 
     def setUp(self):
         super(TestLand, self).setUp()
@@ -112,7 +120,7 @@
         )
         self.assertEqual(
             captured.stdout.getvalue(),
-            'Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!\n'
+            'Landed a5fe8afe9bf7!\n'
             "Delete branch 'eng/example'? ([Yes]/No): \n",
         )
 
@@ -152,7 +160,7 @@
             'Rewrite a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd (1/1) (--- seconds passed, remaining --- predicted)\n'
             'Overwriting a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd\n'
             '1 commit successfully canonicalized!\n'
-            'Landed https://commits.webkit.org/6@main (a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd)!\n'
+            'Landed https://commits.webkit.org/6@main (a5fe8afe9bf7)!\n'
             "Delete branch 'eng/example'? ([Yes]/No): \n",
         )
 
@@ -193,11 +201,140 @@
         )
         self.assertEqual(
             captured.stdout.getvalue(),
-            'Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!\n'
+            'Landed a5fe8afe9bf7!\n'
             "Delete branch 'eng/example'? ([Yes]/No): \n",
         )
 
+    def test_default_with_radar(self):
+        with OutputCapture(level=logging.INFO) as captured, repository(self.path, has_oops=False, issue_url='<rdar://problem/1>'), mocks.local.Svn(), \
+                MockTerminal.input('n'), Environment(RADAR_USERNAME='tcontributor'), bmocks.Radar(issues=bmocks.ISSUES), \
+                patch('webkitbugspy.Tracker._trackers', [radar.Tracker()]):
 
+            self.assertEqual(0, program.main(
+                args=('land', '-v'),
+                path=self.path,
+            ))
+            self.assertEqual(str(local.Git(self.path).commit()), '6@main')
+            self.assertEqual(
+                Tracker.instance().issue(1).comments[-1].content,
+                'Landed a5fe8afe9bf7!',
+            )
+            self.assertFalse(Tracker.instance().issue(1).opened)
+
+        log = captured.root.log.getvalue().splitlines()
+        self.assertEqual(
+            [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
+                "Rebasing 'eng/example' from 'main' to 'main'...",
+                "Rebased 'eng/example' from 'main' to 'main'!",
+            ],
+        )
+        self.assertEqual(
+            captured.stderr.getvalue(),
+            "Failed to find pull-request associated with 'eng/example'\n",
+        )
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            'Landed a5fe8afe9bf7!\n'
+            "Delete branch 'eng/example'? ([Yes]/No): \n",
+        )
+
+    def test_canonicalize_with_bugzilla(self):
+        with OutputCapture(level=logging.INFO) as captured, repository(self.path, has_oops=False, issue_url='{}/show_bug.cgi?id=1'.format(self.BUGZILLA)), \
+                mocks.local.Svn(), MockTerminal.input('n'), patch('webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)]), bmocks.Bugzilla(
+                    self.BUGZILLA.split('://')[-1],
+                    issues=bmocks.ISSUES,
+                    environment=Environment(
+                        BUGS_EXAMPLE_COM_USERNAME='tcontribu...@example.com',
+                        BUGS_EXAMPLE_COM_PASSWORD='password',
+                )):
+
+            self.assertEqual(0, program.main(
+                args=('land', '-v'),
+                path=self.path,
+                identifier_template='Canonical link: https://commits.webkit.org/{}',
+            ))
+            self.assertEqual(
+                Tracker.instance().issue(1).comments[-1].content,
+                'Landed https://commits.webkit.org/6@main (a5fe8afe9bf7)!',
+            )
+            self.assertFalse(Tracker.instance().issue(1).opened)
+
+            commit = local.Git(self.path).commit(branch='main')
+            self.assertEqual(str(commit), '6@main')
+            self.assertEqual(
+                commit.message,
+                'To Be Committed\n'
+                'https://bugs.example.com/show_bug.cgi?id=1\n\n'
+                'Reviewed by Ricky Reviewer.\n\n'
+                'Canonical link: https://commits.webkit.org/6@main',
+            )
+
+        log = captured.root.log.getvalue().splitlines()
+        self.assertEqual(
+            [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
+                "Rebasing 'eng/example' from 'main' to 'main'...",
+                "Rebased 'eng/example' from 'main' to 'main'!",
+                '1 commit to be editted...',
+                'Base commit is 5@main (ref d8bce26fa65c6fc8f39c17927abb77f69fab82fc)',
+            ],
+        )
+        self.assertEqual(
+            captured.stderr.getvalue(),
+            "Failed to find pull-request associated with 'eng/example'\n",
+        )
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            'Rewrite a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd (1/1) (--- seconds passed, remaining --- predicted)\n'
+            'Overwriting a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd\n'
+            '1 commit successfully canonicalized!\n'
+            'Landed https://commits.webkit.org/6@main (a5fe8afe9bf7)!\n'
+            "Delete branch 'eng/example'? ([Yes]/No): \n",
+        )
+
+    def test_svn_with_bugzilla(self):
+        with MockTime, OutputCapture(level=logging.INFO) as captured, \
+                repository(self.path, has_oops=False, git_svn=True, issue_url='{}/show_bug.cgi?id=1'.format(self.BUGZILLA)), \
+                mocks.local.Svn(), MockTerminal.input('n'), patch('webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)]), \
+                bmocks.Bugzilla(
+                    self.BUGZILLA.split('://')[-1],
+                    issues=bmocks.ISSUES,
+                    environment=Environment(
+                        BUGS_EXAMPLE_COM_USERNAME='tcontribu...@example.com',
+                        BUGS_EXAMPLE_COM_PASSWORD='password',
+                )):
+
+            self.assertEqual(0, program.main(
+                args=('land', '-v'),
+                path=self.path, canonical_svn=True,
+            ))
+            self.assertEqual(str(local.Git(self.path).commit()), '6@main')
+            self.assertEqual(
+                Tracker.instance().issue(1).comments[-1].content,
+                'Landed r10!',
+            )
+            self.assertFalse(Tracker.instance().issue(1).opened)
+
+        log = captured.root.log.getvalue().splitlines()
+        self.assertEqual(
+            [line for line in log if 'Mock process' not in line], [
+                '    Found 1 commit...',
+                "Rebasing 'eng/example' from 'main' to 'main'...",
+                "Rebased 'eng/example' from 'main' to 'main'!",
+                '    Verifying mirror processesed change',
+            ],
+        )
+        self.assertEqual(
+            captured.stderr.getvalue(),
+            "Failed to find pull-request associated with 'eng/example'\n",
+        )
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            'Landed a5fe8afe9bf7!\n'
+            "Delete branch 'eng/example'? ([Yes]/No): \n",
+        )
+
 class TestLandGitHub(testing.PathTestCase):
     basepath = 'mock/repository'
 
@@ -304,7 +441,7 @@
             self.assertEqual(str(repo.commit()), '6@main')
             self.assertEqual(
                 [comment.content for comment in repo.remote().pull_requests.get(1).comments],
-                ['Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!'],
+                ['Landed a5fe8afe9bf7!'],
             )
 
         log = captured.root.log.getvalue().splitlines()
@@ -321,7 +458,7 @@
         self.assertEqual(
             captured.stdout.getvalue(),
             "Set 'Ricky Reviewer' as your reviewer? ([Yes]/No): \n"
-            'Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!\n'
+            'Landed a5fe8afe9bf7!\n'
             "Delete branch 'eng/example'? ([Yes]/No): \n",
         )
 
@@ -433,7 +570,7 @@
             self.assertEqual(str(repo.commit()), '6@main')
             self.assertEqual(
                 [comment.content for comment in repo.remote().pull_requests.get(1).comments],
-                ['Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!'],
+                ['Landed a5fe8afe9bf7!'],
             )
 
         log = captured.root.log.getvalue().splitlines()
@@ -450,6 +587,6 @@
         self.assertEqual(
             captured.stdout.getvalue(),
             "Set 'Ricky Reviewer' as your reviewer? ([Yes]/No): \n"
-            'Landed a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd!\n'
+            'Landed a5fe8afe9bf7!\n'
             "Delete branch 'eng/example'? ([Yes]/No): \n",
         )
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to