Title: [280440] trunk/Tools
Revision
280440
Author
jbed...@apple.com
Date
2021-07-29 12:47:47 -0700 (Thu, 29 Jul 2021)

Log Message

[webkitscmpy] Return remote objects from remote() function
https://bugs.webkit.org/show_bug.cgi?id=226980
<rdar://problem/79299760>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.url): Add function to return remote url directly.
(Git.remote): Construct the appropriate remote object.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
(Svn.url): Add function to return the remote url directly.
(Svn.remote): Construct the appropriate remote object.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
(TestGit.test_url):
(TestGit.test_remote):
(TestGit.test_remote_github):
(TestGit.test_remote_bitbucket):
* Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py:
(TestLocalSvn.test_url):
(TestLocalSvn.test_remote):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (280439 => 280440)


--- trunk/Tools/ChangeLog	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/ChangeLog	2021-07-29 19:47:47 UTC (rev 280440)
@@ -1,3 +1,28 @@
+2021-07-29  Jonathan Bedard  <jbed...@apple.com>
+
+        [webkitscmpy] Return remote objects from remote() function
+        https://bugs.webkit.org/show_bug.cgi?id=226980
+        <rdar://problem/79299760>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+        (Git.url): Add function to return remote url directly.
+        (Git.remote): Construct the appropriate remote object.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
+        (Svn.url): Add function to return the remote url directly.
+        (Svn.remote): Construct the appropriate remote object.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
+        (TestGit.test_url):
+        (TestGit.test_remote):
+        (TestGit.test_remote_github):
+        (TestGit.test_remote_bitbucket):
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py:
+        (TestLocalSvn.test_url):
+        (TestLocalSvn.test_remote):
+
 2021-07-29  Peng Liu  <peng.l...@apple.com>
 
         [Catalina][GPUP] Some API tests fail after GPU Process features are enabled

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='1.0.0',
+    version='1.0.1',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(1, 0, 0)
+version = Version(1, 0, 1)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('monotonic', Version(1, 5)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -34,6 +34,7 @@
 
 from webkitcorepy import run, decorators, NestedFuzzyDict
 from webkitscmpy.local import Scm
+from webkitscmpy import remote, Commit, Contributor, log
 from webkitscmpy import Commit, Contributor, log
 
 
@@ -253,6 +254,8 @@
 
 
     GIT_COMMIT = re.compile(r'commit (?P<hash>[0-9a-f]+)')
+    SSH_REMOTE = re.compile('(ssh://)?git@(?P<host>.+):(?P<path>.+).git')
+    HTTP_REMOTE = re.compile('(?P<protocol>https?)://(?P<host>.+)/(?P<path>.+).git')
 
     @classmethod
     @decorators.Memoize()
@@ -351,12 +354,37 @@
             raise self.Exception('Failed to retrieve tag list for {}'.format(self.root_path))
         return tags.stdout.splitlines()
 
-    def remote(self, name=None):
+    @decorators.Memoize()
+    def url(self, name=None):
         result = run([self.executable(), 'remote', 'get-url', name or 'origin'], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if result.returncode:
             raise self.Exception('Failed to retrieve remote for {}'.format(self.root_path))
         return result.stdout.rstrip()
 
+    @decorators.Memoize()
+    def remote(self, name=None):
+        url = ""
+        ssh_match = self.SSH_REMOTE.match(url)
+        http_match = self.HTTP_REMOTE.match(url)
+        if ssh_match:
+            url = ''.format(ssh_match.group('host'), ssh_match.group('path'))
+        elif http_match:
+            url = ''.format(http_match.group('protocol'), http_match.group('host'), http_match.group('path'))
+
+        if remote.GitHub.is_webserver(url):
+            return remote.GitHub(url, contributors=self.contributors)
+        if 'bitbucket' in url or 'stash' in url:
+            match = re.match(r'(?P<protocol>https?)://(?P<host>.+)/(?P<project>.+)/(?P<repo>.+)', url)
+            return remote.BitBucket(
+                '{}://{}/projects/{}/repos/{}'.format(
+                    match.group('protocol'),
+                    match.group('host'),
+                    match.group('project').upper(),
+                    match.group('repo'),
+                ), contributors=self.contributors,
+            )
+        return None
+
     def _commit_count(self, native_parameter):
         revision_count = run(
             [self.executable(), 'rev-list', '--count', '--no-merges', native_parameter],

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -35,7 +35,7 @@
 
 from webkitcorepy import log, run, decorators
 from webkitscmpy.local.scm import Scm
-from webkitscmpy import Commit, Contributor, Version
+from webkitscmpy import remote, Commit, Contributor, Version
 
 
 class Svn(Scm):
@@ -297,9 +297,13 @@
             return len(self.cache._data[branch])
         return self._commit_count(revision=self.cache._data[branch][0], branch=self.default_branch)
 
-    def remote(self, name=None):
+    def url(self, name=None):
         return self.info(cached=True)['Repository Root']
 
+    @decorators.Memoize()
+    def remote(self, name=None):
+        return remote.Svn(self.url(name=name), contributors=self.contributors)
+
     def _branch_for(self, revision):
         if not self.cache:
             raise self.Exception('No available cache, cannot determine branch')
@@ -311,7 +315,7 @@
             return candidate
 
         process = run(
-            [self.executable(), 'log', '-v', '-q', self.remote(), '-r', str(revision), '-l', '1'],
+            [self.executable(), 'log', '-v', '-q', self.url(), '-r', str(revision), '-l', '1'],
             cwd=self.root_path, capture_output=True, encoding='utf-8',
         )
 

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -54,10 +54,26 @@
         with mocks.local.Git(self.path, detached=True):
             self.assertEqual(local.Git(self.path).branch, None)
 
-    def test_remote(self):
+    def test_url(self):
         with mocks.local.Git(self.path) as repo:
-            self.assertEqual(local.Git(self.path).remote(), repo.remote)
+            self.assertEqual(local.Git(self.path).url(), repo.remote)
 
+    def test_remote(self):
+        with mocks.local.Git(self.path):
+            self.assertEqual(local.Git(self.path).remote(), None)
+
+    def test_remote_github(self):
+        with mocks.local.Git(self.path, remote='g...@github.example.com:WebKit/WebKit.git'):
+            self.assertIsInstance(local.Git(self.path).remote(), remote.GitHub)
+        with mocks.local.Git(self.path, remote='https://github.example.com/WebKit/WebKit.git'):
+            self.assertIsInstance(local.Git(self.path).remote(), remote.GitHub)
+
+    def test_remote_bitbucket(self):
+        with mocks.local.Git(self.path, remote='ssh://g...@stash.example.com:webkit/webkit.git'):
+            self.assertIsInstance(local.Git(self.path).remote(), remote.BitBucket)
+        with mocks.local.Git(self.path, remote='http://g...@stash.example.com/webkit/webkit.git'):
+            self.assertIsInstance(local.Git(self.path).remote(), remote.BitBucket)
+
     def test_branches(self):
         with mocks.local.Git(self.path):
             self.assertEqual(

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py (280439 => 280440)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py	2021-07-29 19:04:52 UTC (rev 280439)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py	2021-07-29 19:47:47 UTC (rev 280440)
@@ -50,9 +50,13 @@
         with mocks.local.Svn(self.path):
             self.assertEqual(local.Svn(self.path).branch, 'trunk')
 
+    def test_url(self):
+        with mocks.local.Svn(self.path) as repo:
+            self.assertEqual(local.Svn(self.path).url(), repo.remote)
+
     def test_remote(self):
         with mocks.local.Svn(self.path) as repo:
-            self.assertEqual(local.Svn(self.path).remote(), repo.remote)
+            self.assertIsInstance(local.Svn(self.path).remote(), remote.Svn)
 
     def test_branches(self):
         with mocks.local.Svn(self.path):
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to