Title: [289684] trunk/Tools
Revision
289684
Author
[email protected]
Date
2022-02-11 17:45:56 -0800 (Fri, 11 Feb 2022)

Log Message

[git-webkit] Link issue to pull requests
https://bugs.webkit.org/show_bug.cgi?id=236339
<rdar://problem/88657772>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.main): Add link to pull request in issue comments, assign issue to
pull request author.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (289683 => 289684)


--- trunk/Tools/ChangeLog	2022-02-12 01:35:41 UTC (rev 289683)
+++ trunk/Tools/ChangeLog	2022-02-12 01:45:56 UTC (rev 289684)
@@ -1,5 +1,20 @@
 2022-02-09  Jonathan Bedard  <[email protected]>
 
+        [git-webkit] Link issue to pull requests
+        https://bugs.webkit.org/show_bug.cgi?id=236339
+        <rdar://problem/88657772>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
+        (PullRequest.main): Add link to pull request in issue comments, assign issue to
+        pull request author.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:
+
+2022-02-09  Jonathan Bedard  <[email protected]>
+
         [EWS] Rebase PRs on tip of branch
         https://bugs.webkit.org/show_bug.cgi?id=236389
         <rdar://problem/88705147>

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (289683 => 289684)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-12 01:35:41 UTC (rev 289683)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-02-12 01:45:56 UTC (rev 289684)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.1.2',
+    version='4.1.3',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (289683 => 289684)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-12 01:35:41 UTC (rev 289683)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-02-12 01:45:56 UTC (rev 289684)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 1, 2)
+version = Version(4, 1, 3)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-02-12 01:35:41 UTC (rev 289683)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2022-02-12 01:45:56 UTC (rev 289684)
@@ -27,6 +27,7 @@
 from .command import Command
 from .branch import Branch
 
+from webkitbugspy import Tracker
 from webkitcorepy import arguments, run, Terminal
 from webkitscmpy import local, log, remote
 
@@ -207,6 +208,12 @@
             existing_pr = None
         commits = list(repository.commits(begin=dict(hash=branch_point.hash), end=dict(branch=repository.branch)))
 
+        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
+
         if existing_pr:
             log.info("Updating pull-request for '{}'...".format(repository.branch))
             pr = rmt.pull_requests.update(
@@ -233,6 +240,17 @@
                 sys.stderr.write("Failed to create pull-request for '{}'\n".format(repository.branch))
                 return 1
             print("Created '{}'!".format(pr))
+
+        if issue:
+            log.info('Checking issue assignee...')
+            if issue.assignee != issue.tracker.me():
+                issue.assign(issue.tracker.me())
+                print('Assigning associated issue to {}'.format(issue.tracker.me()))
+            log.info('Checking for pull request link in associated issue...')
+            if pr.url and not any([pr.url in comment.content for comment in issue.comments]):
+                issue.add_comment('Pull request: {}'.format(pr.url))
+                print('Posted pull request link to {}'.format(issue.link))
+
         if pr.url:
             print(pr.url)
 

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-02-12 01:35:41 UTC (rev 289683)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py	2022-02-12 01:45:56 UTC (rev 289684)
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 Apple Inc. All rights reserved.
+# Copyright (C) 2021-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
@@ -23,11 +23,13 @@
 import logging
 import os
 import sys
+import time
 import unittest
 
-from webkitbugspy import User
+from mock import patch
+from webkitbugspy import Tracker, User, bugzilla, radar, mocks as bmocks
 from webkitcorepy import OutputCapture, testing, log as wcplog
-from webkitcorepy.mocks import Terminal as MockTerminal
+from webkitcorepy.mocks import Terminal as MockTerminal, Environment
 from webkitscmpy import Contributor, Commit, PullRequest, local, program, mocks, remote, log as wsplog
 
 
@@ -250,6 +252,7 @@
 
 class TestDoPullRequest(testing.PathTestCase):
     basepath = 'mock/repository'
+    BUGZILLA = 'https://bugs.example.com'
 
     def setUp(self):
         super(TestDoPullRequest, self).setUp()
@@ -461,6 +464,58 @@
             ],
         )
 
+    def test_github_bugzilla(self):
+        with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, bmocks.Bugzilla(
+            self.BUGZILLA.split('://')[-1],
+            issues=bmocks.ISSUES,
+            environment=Environment(
+                BUGS_EXAMPLE_COM_USERNAME='[email protected]',
+                BUGS_EXAMPLE_COM_PASSWORD='password',
+            )), patch(
+                'webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)],
+        ), mocks.local.Git(self.path, remote='https://{}'.format(remote.remote)) as repo, mocks.local.Svn():
+
+            repo.commits['eng/pr-branch'] = [Commit(
+                hash='06de5d56554e693db72313f4ca1fb969c30b8ccb',
+                branch='eng/pr-branch',
+                author=dict(name='Tim Contributor', emails=['[email protected]']),
+                identifier="5.1@eng/pr-branch",
+                timestamp=int(time.time()),
+                message='[Testing] Existing commit\nbugs.example.com/show_bug.cgi?id=1'
+            )]
+            repo.head = repo.commits['eng/pr-branch'][-1]
+            self.assertEqual(0, program.main(
+                args=('pull-request', '-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',
+            )
+
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            "Created 'PR 1 | [Testing] Existing commit'!\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], [
+                '    Found 1 commit...',
+                "Using committed changes...",
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
+                "    Found 1 commit...",
+                "Pushing 'eng/pr-branch' to 'fork'...",
+                "Creating pull-request for 'eng/pr-branch'...",
+                'Checking issue assignee...',
+                'Checking for pull request link in associated issue...',
+            ],
+        )
+
     def test_bitbucket(self):
         with OutputCapture(level=logging.INFO) as captured, mocks.remote.BitBucket() as remote, mocks.local.Git(self.path, remote='ssh://git@{}/{}/{}.git'.format(
             remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3],
@@ -612,7 +667,53 @@
             ],
         )
 
+    def test_bitbucket_radar(self):
+        with OutputCapture(level=logging.INFO) as captured, mocks.remote.BitBucket() as remote, mocks.local.Git(
+            self.path, remote='ssh://git@{}/{}/{}.git'.format(remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3]),
+        ) as repo, mocks.local.Svn(), Environment(RADAR_USERNAME='tcontributor'), bmocks.Radar(issues=bmocks.ISSUES), patch('webkitbugspy.Tracker._trackers', [radar.Tracker()]):
 
+            repo.commits['eng/pr-branch'] = [Commit(
+                hash='06de5d56554e693db72313f4ca1fb969c30b8ccb',
+                branch='eng/pr-branch',
+                author=dict(name='Tim Contributor', emails=['[email protected]']),
+                identifier="5.1@eng/pr-branch",
+                timestamp=int(time.time()),
+                message='<rdar://problem/1> [Testing] Existing commit\n'
+            )]
+            repo.head = repo.commits['eng/pr-branch'][-1]
+            self.assertEqual(0, program.main(
+                args=('pull-request', '-v', '--no-history'),
+                path=self.path,
+            ))
+
+            self.assertEqual(
+                Tracker.instance().issue(1).comments[-1].content,
+                'Pull request: https://bitbucket.example.com/projects/WEBKIT/repos/webkit/pull-requests/1/overview',
+            )
+
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            "Created 'PR 1 | <rdar://problem/1> [Testing] Existing commit'!\n"
+            'Posted pull request link to <rdar://1>\n'
+            'https://bitbucket.example.com/projects/WEBKIT/repos/webkit/pull-requests/1/overview\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], [
+                '    Found 1 commit...',
+                "Using committed changes...",
+                "Rebasing 'eng/pr-branch' on 'main'...",
+                "Rebased 'eng/pr-branch' on 'main!'",
+                "    Found 1 commit...",
+                "Pushing 'eng/pr-branch' to 'origin'...",
+                "Creating pull-request for 'eng/pr-branch'...",
+                'Checking issue assignee...',
+                'Checking for pull request link in associated issue...',
+            ],
+        )
+
+
 class TestNetworkPullRequestGitHub(unittest.TestCase):
     remote = 'https://github.example.com/WebKit/WebKit'
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to