Title: [229600] trunk/Tools
Revision
229600
Author
[email protected]
Date
2018-03-14 09:11:03 -0700 (Wed, 14 Mar 2018)

Log Message

Add label on github when exporting wpt tests to w3c/web-platform-test repo
https://bugs.webkit.org/show_bug.cgi?id=183575

Patch by Brendan McLoughlin <[email protected]> on 2018-03-14
Reviewed by Youenn Fablet.

* Scripts/webkitpy/w3c/test_exporter.py:
(TestExporter.make_pull_request):
(parse_args):
* Scripts/webkitpy/w3c/test_exporter_unittest.py:
(TestExporterTest.test_export):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (229599 => 229600)


--- trunk/Tools/ChangeLog	2018-03-14 14:48:39 UTC (rev 229599)
+++ trunk/Tools/ChangeLog	2018-03-14 16:11:03 UTC (rev 229600)
@@ -1,3 +1,16 @@
+2018-03-14  Brendan McLoughlin  <[email protected]>
+
+        Add label on github when exporting wpt tests to w3c/web-platform-test repo
+        https://bugs.webkit.org/show_bug.cgi?id=183575
+
+        Reviewed by Youenn Fablet.
+
+        * Scripts/webkitpy/w3c/test_exporter.py:
+        (TestExporter.make_pull_request):
+        (parse_args):
+        * Scripts/webkitpy/w3c/test_exporter_unittest.py:
+        (TestExporterTest.test_export):
+
 2018-03-14  Zalan Bujtas  <[email protected]>
 
         [LayoutReloaded] Add InlineBox dump

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py (229599 => 229600)


--- trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py	2018-03-14 14:48:39 UTC (rev 229599)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py	2018-03-14 16:11:03 UTC (rev 229600)
@@ -39,6 +39,7 @@
 
 WEBKIT_WPT_DIR = 'LayoutTests/imported/w3c/web-platform-tests'
 WPT_PR_URL = "https://github.com/w3c/web-platform-tests/pull/"
+WEBKIT_EXPORT_PR_LABEL = 'webkit-export'
 
 
 class TestExporter(object):
@@ -177,10 +178,28 @@
 
         _log.info('Making pull request')
         description = self._bugzilla.fetch_bug_dictionary(self._bug_id)["title"]
-        pr_number = self._github.create_pr(self._wpt_fork_remote + ':' + self._branch_name, self._commit_message, self._commit_message + "\n" + description)
-        if self._bug_id:
+        pr_number = self.create_wpt_pull_request(self._wpt_fork_remote + ':' + self._public_branch_name, self._commit_message, self._commit_message + "\n" + description)
+        if pr_number:
+            try:
+                self._github.add_label(pr_number, WEBKIT_EXPORT_PR_LABEL)
+            except Exception as e:
+                _log.warning(e)
+                _log.info('Could not add label "%s" to pr #%s. User "%s" may not have permission to update labels in the w3c/web-platform-test repo.' % (WEBKIT_EXPORT_PR_LABEL, pr_number, self._username))
+        if self._bug_id and pr_number:
             self._bugzilla.post_comment_to_bug(self._bug_id, "Submitted web-platform-tests pull request: " + WPT_PR_URL + str(pr_number))
 
+    def create_wpt_pull_request(self, remote_branch_name, title, body):
+        pr_number = None
+        try:
+            pr_number = self._github.create_pr(remote_branch_name, title, body)
+        except Exception as e:
+            if e.code == 422:
+                _log.info('Unable to create a new pull request for branch "%s" because a pull request already exists. The branch has been updated and there is no further action needed.' % (remote_branch_name))
+            else:
+                _log.warning(e)
+                _log.info('Error creating a pull request on github. Please ensure that the provided github token has the "public_repo" scope.')
+        return pr_number
+
     def delete_local_branch(self):
         _log.info('Removing branch ' + self._branch_name)
         self._git.checkout('master')
@@ -246,7 +265,6 @@
     - As a dry run, one can start by running the script without -c. This will only create the branch on the user public GitHub repository.
     - By default, the script will create an https remote URL that will require a password-based authentication to GitHub. If you are using an SSH key, please use the --remote-url option.
     FIXME:
-    - Add a label on github issues
     - The script is not yet able to update an existing pull request
     - Need a way to monitor the progress of the pul request so that status of all pending pull requests can be done at import time.
     """

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py (229599 => 229600)


--- trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py	2018-03-14 14:48:39 UTC (rev 229599)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py	2018-03-14 16:11:03 UTC (rev 229600)
@@ -110,7 +110,7 @@
         options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
         exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub)
         exporter.do_export()
-        self.assertEquals(exporter._github.calls, ['create_pr'])
+        self.assertEquals(exporter._github.calls, ['create_pr', 'add_label "webkit-export"'])
         self.assertTrue('WebKit export' in exporter._github.pull_requests_created[0][1])
         self.assertEquals(exporter._git.calls, [
             '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests',
@@ -131,3 +131,25 @@
         self.assertEquals(exporter._bugzilla.calls, [
             'fetch bug 1234',
             'post comment to bug 1234 : Submitted web-platform-tests pull request: https://github.com/w3c/web-platform-tests/pull/5678'])
+
+    def test_export_with_specific_branch(self):
+        host = TestExporterTest.MyMockHost()
+        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN', '-bn', 'wpt-export-branch'])
+        exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub)
+        exporter.do_export()
+        self.assertEquals(exporter._git.calls, [
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests',
+            'fetch',
+            'checkout master',
+            'reset hard origin/master',
+            'checkout new branch wpt-export-for-webkit-1234',
+            'apply_mail_patch patch.temp --exclude *-expected.txt',
+            'commit -a -m WebKit export of https://bugs.webkit.org/show_bug.cgi?id=1234',
+            'remote ',
+            'remote add USER https://[email protected]/USER/web-platform-tests.git',
+            'remote get-url USER',
+            'push USER wpt-export-for-webkit-1234:wpt-export-branch -f',
+            'checkout master',
+            'delete branch wpt-export-for-webkit-1234',
+            'checkout master',
+            'reset hard origin/master'])
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to