Title: [290748] trunk/Tools
Revision
290748
Author
[email protected]
Date
2022-03-02 12:53:00 -0800 (Wed, 02 Mar 2022)

Log Message

[git-webkit] Derive branch name from bug title
https://bugs.webkit.org/show_bug.cgi?id=237284
<rdar://problem/89578241 >

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/branch.py:
(Branch.to_branch_name): Convert string (particularly a bug title) to potential branch name.
(Branch.main): If provided branch name is actually a bug number or URL, use the title
of that bug as the branch name.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py:
(TestBranch):
(TestBranch.test_prompt_git):
(TestBranch.test_prompt_number):
(TestBranch.test_prompt_url):
(TestBranch.test_invalid_branch):
(TestBranch.test_to_branch_name):

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (290747 => 290748)


--- trunk/Tools/ChangeLog	2022-03-02 20:41:37 UTC (rev 290747)
+++ trunk/Tools/ChangeLog	2022-03-02 20:53:00 UTC (rev 290748)
@@ -1,5 +1,27 @@
 2022-03-02  Jonathan Bedard  <[email protected]>
 
+        [git-webkit] Derive branch name from bug title
+        https://bugs.webkit.org/show_bug.cgi?id=237284
+        <rdar://problem/89578241 >
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
+        (Branch.to_branch_name): Convert string (particularly a bug title) to potential branch name.
+        (Branch.main): If provided branch name is actually a bug number or URL, use the title
+        of that bug as the branch name.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py:
+        (TestBranch):
+        (TestBranch.test_prompt_git):
+        (TestBranch.test_prompt_number):
+        (TestBranch.test_prompt_url):
+        (TestBranch.test_invalid_branch):
+        (TestBranch.test_to_branch_name):
+
+2022-03-02  Jonathan Bedard  <[email protected]>
+
         [git-webkit] Sync personal fork by default
         https://bugs.webkit.org/show_bug.cgi?id=237324
         <rdar://problem/89618617>

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (290747 => 290748)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-03-02 20:41:37 UTC (rev 290747)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-03-02 20:53:00 UTC (rev 290748)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.3.5',
+    version='4.3.6',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (290747 => 290748)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-03-02 20:41:37 UTC (rev 290747)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-03-02 20:53:00 UTC (rev 290748)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 3, 5)
+version = Version(4, 3, 6)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2022-03-02 20:41:37 UTC (rev 290747)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2022-03-02 20:53:00 UTC (rev 290748)
@@ -25,6 +25,7 @@
 
 from .command import Command
 
+from webkitbugspy import Tracker
 from webkitcorepy import run, string_utils, Terminal
 from webkitscmpy import local, log
 
@@ -70,6 +71,16 @@
         return commit
 
     @classmethod
+    def to_branch_name(cls, value):
+        result = ''
+        for c in string_utils.decode(value):
+            if c in [u'-', u' ', u'\n', u'\t', u'.']:
+                result += u'-'
+            elif c.isalnum() or c == u'_':
+                result += c
+        return string_utils.encode(result, target_type=str)
+
+    @classmethod
     def main(cls, args, repository, why=None, **kwargs):
         if not isinstance(repository, local.Git):
             sys.stderr.write("Can only 'branch' on a native Git repository\n")
@@ -76,7 +87,17 @@
             return 1
 
         if not args.issue:
-            args.issue = Terminal.input('{}nter name of new branch: '.format('{}, e'.format(why) if why else 'E'))
+            args.issue = Terminal.input('{}nter name of new branch (or bug URL): '.format('{}, e'.format(why) if why else 'E'))
+
+        if string_utils.decode(args.issue).isnumeric() and Tracker.instance():
+            issue = Tracker.instance().issue(int(args.issue))
+            if issue and issue.title:
+                args.issue = cls.to_branch_name(issue.title)
+        else:
+            issue = Tracker.from_string(args.issue)
+            if issue and issue.title:
+                args.issue = cls.to_branch_name(issue.title)
+
         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/test/branch_unittest.py (290747 => 290748)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py	2022-03-02 20:41:37 UTC (rev 290747)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py	2022-03-02 20:53:00 UTC (rev 290748)
@@ -20,20 +20,19 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import json
 import logging
 import os
-import shutil
-import tempfile
 
-from datetime import datetime
+from mock import patch
+from webkitbugspy import bugzilla, mocks as bmocks, radar
 from webkitcorepy import OutputCapture, testing
-from webkitcorepy.mocks import Time as MockTime, Terminal as MockTerminal
+from webkitcorepy.mocks import Time as MockTime, Terminal as MockTerminal, Environment
 from webkitscmpy import local, program, mocks
 
 
 class TestBranch(testing.PathTestCase):
     basepath = 'mock/repository'
+    BUGZILLA = 'https://bugs.example.com'
 
     def setUp(self):
         super(TestBranch, self).setUp()
@@ -63,8 +62,31 @@
             self.assertEqual(0, program.main(args=('branch', '-v'), path=self.path))
             self.assertEqual(local.Git(self.path).branch, 'eng/example')
         self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/example'...\n")
-        self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch: \nCreated the local development branch 'eng/example'\n")
+        self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch (or bug URL): \nCreated the local development branch 'eng/example'\n")
 
+    def test_prompt_number(self):
+        with MockTerminal.input('2'), OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path), 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.Svn(), MockTime:
+            self.assertEqual(0, program.main(args=('branch', '-v'), path=self.path))
+            self.assertEqual(local.Git(self.path).branch, 'eng/Example-feature-1')
+        self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/Example-feature-1'...\n")
+        self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch (or bug URL): \nCreated the local development branch 'eng/Example-feature-1'\n")
+
+    def test_prompt_url(self):
+        with MockTerminal.input('<rdar://2>'), OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path), \
+            bmocks.Radar(issues=bmocks.ISSUES), patch('webkitbugspy.Tracker._trackers', [radar.Tracker()]), mocks.local.Svn(), MockTime:
+
+            self.assertEqual(0, program.main(args=('branch', '-v'), path=self.path))
+            self.assertEqual(local.Git(self.path).branch, 'eng/Example-feature-1')
+        self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/Example-feature-1'...\n")
+        self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch (or bug URL): \nCreated the local development branch 'eng/Example-feature-1'\n")
+
     def test_invalid_branch(self):
         with OutputCapture() as captured, mocks.local.Git(self.path), mocks.local.Svn(), MockTime:
             self.assertEqual(1, program.main(
@@ -72,3 +94,9 @@
                 path=self.path,
             ))
         self.assertEqual(captured.stderr.getvalue(), "'eng/reject_underscores' is an invalid branch name, cannot create it\n")
+
+    def test_to_branch_name(self):
+        self.assertEqual(program.Branch.to_branch_name('something with spaces'), 'something-with-spaces')
+        self.assertEqual(program.Branch.to_branch_name('[EWS] bug description'), 'EWS-bug-description')
+        self.assertEqual(program.Branch.to_branch_name('[git-webkit] change'), 'git-webkit-change')
+        self.assertEqual(program.Branch.to_branch_name('Add Terminal.open_url'), 'Add-Terminal-open_url')
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to