Title: [293476] trunk/Tools
Revision
293476
Author
[email protected]
Date
2022-04-26 15:36:52 -0700 (Tue, 26 Apr 2022)

Log Message

[git-webkit] Checkout PRs from alternate remotes
https://bugs.webkit.org/show_bug.cgi?id=239745
<rdar://problem/92300209>

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/local/git.py:
(Git): The name of the repository is embedded in the argument.
(Git.checkout): Handle remote-postfixed remote names.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py:
(Checkout.parser): Add --remote command.
(Checkout.main): Use the full repo name instead of the owner's username.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:
(GitHub.PRGenerator.PullRequest): Pass full repo name as metadata.

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

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (293475 => 293476)


--- trunk/Tools/ChangeLog	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/ChangeLog	2022-04-26 22:36:52 UTC (rev 293476)
@@ -1,5 +1,24 @@
 2022-04-26  Jonathan Bedard  <[email protected]>
 
+        [git-webkit] Checkout PRs from alternate remotes
+        https://bugs.webkit.org/show_bug.cgi?id=239745
+        <rdar://problem/92300209>
+
+        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): The name of the repository is embedded in the argument.
+        (Git.checkout): Handle remote-postfixed remote names.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py:
+        (Checkout.parser): Add --remote command.
+        (Checkout.main): Use the full repo name instead of the owner's username.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:
+        (GitHub.PRGenerator.PullRequest): Pass full repo name as metadata.
+
+2022-04-26  Jonathan Bedard  <[email protected]>
+
         [build.webkit.org] Support identifiers in popover
         https://bugs.webkit.org/show_bug.cgi?id=239773
         <rdar://problem/92339575>

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (293475 => 293476)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-04-26 22:36:52 UTC (rev 293476)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.11.1',
+    version='4.11.2',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (293475 => 293476)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-04-26 22:36:52 UTC (rev 293476)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 11, 1)
+version = Version(4, 11, 2)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

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


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2022-04-26 22:36:52 UTC (rev 293476)
@@ -301,7 +301,7 @@
     SSH_REMOTE = re.compile('(ssh://)?git@(?P<host>[^:/]+)[:/](?P<path>.+).git')
     HTTP_REMOTE = re.compile(r'(?P<protocol>https?)://(?P<host>[^\/]+)/(?P<path>.+).git')
     REMOTE_BRANCH = re.compile(r'remotes\/(?P<remote>[^\/]+)\/(?P<branch>.+)')
-    USER_REMOTE = re.compile(r'(?P<username>[^:/]+):(?P<branch>.+)')
+    USER_REMOTE = re.compile(r'(?P<name>[^:]+):(?P<branch>.+)')
     GIT_CONFIG_EXTENSION = 'git_config_extension'
     PROJECT_CONFIG_OPTIONS = {
         'pull.rebase': ['true', 'false'],
@@ -864,34 +864,38 @@
         match = self.USER_REMOTE.match(argument)
         rmt = self.remote()
         if match and isinstance(rmt, remote.GitHub):
-            username = match.group('username')
-            if not self.url(match.group('username')):
+            name = match.group('name')
+            username = name.split('/')[0]
+            repo_name = rmt.name if '/' not in name else name.split('/', 1)[-1]
+            name = username + repo_name[len(rmt.name):]
+
+            if not self.url(name):
                 url = ""
                 if '://' in url:
-                    rmt = '{}://{}/{}/{}.git'.format(url.split(':')[0], url.split('/')[2], username, rmt.name)
+                    rmt = '{}://{}/{}/{}.git'.format(url.split(':')[0], url.split('/')[2], username, repo_name)
                 elif ':' in url:
-                    rmt = '{}:{}/{}.git'.format(url.split(':')[0], username, rmt.name)
+                    rmt = '{}:{}/{}.git'.format(url.split(':')[0], username, repo_name)
                 else:
                     sys.stderr.write("Failed to convert '{}' to '{}' remote\n".format(url, username))
                     return None
                 if run(
-                    [self.executable(), 'remote', 'add', username, rmt],
+                    [self.executable(), 'remote', 'add', name, rmt],
                     capture_output=True, cwd=self.root_path,
                 ).returncode:
-                    sys.stderr.write("Failed to add remote '{}' as '{}'\n".format(rmt, username))
+                    sys.stderr.write("Failed to add remote '{}' as '{}'\n".format(rmt, name))
                     return None
                 self.config.clear()
             branch = match.group('branch')
             rc = run(
-                [self.executable(), 'checkout'] + ['-B', branch, '{}/{}'.format(username, branch)] + log_arg,
+                [self.executable(), 'checkout'] + ['-B', branch, '{}/{}'.format(name, branch)] + log_arg,
                 cwd=self.root_path,
             ).returncode
             if not rc:
                 return self.commit()
             if rc == 128:
-                run([self.executable(), 'fetch', username], cwd=self.root_path)
+                run([self.executable(), 'fetch', name], cwd=self.root_path)
             return None if run(
-                [self.executable(), 'checkout'] + ['-B', branch, '{}/{}'.format(username, branch)] + log_arg,
+                [self.executable(), 'checkout'] + ['-B', branch, '{}/{}'.format(name, branch)] + log_arg,
                 cwd=self.root_path,
             ).returncode else self.commit()
 

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py (293475 => 293476)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py	2022-04-26 22:36:52 UTC (rev 293476)
@@ -41,6 +41,10 @@
             type=str, default=None,
             help='String representation of a commit or branch to be normalized',
         )
+        parser.add_argument(
+            '--remote', dest='remote', type=str, default=None,
+            help='Specify remote to search for pull request from.',
+        )
 
     @classmethod
     def main(cls, args, repository, **kwargs):
@@ -54,7 +58,7 @@
         target = args.argument[0]
         match = cls.PR_RE.match(target)
         if match:
-            rmt = repository.remote()
+            rmt = repository.remote(name=args.remote)
             if not rmt:
                 sys.stderr.write('Repository does not have associated remote\n')
                 return 1
@@ -65,11 +69,16 @@
             if not pr:
                 sys.stderr.write("Failed to find 'PR-{}' associated with this repository\n".format(match.group('number')))
                 return 1
-            if isinstance(rmt, remote.GitHub) and pr.author.github:
-                target = '{}:{}'.format(pr.author.github, pr.head)
+
+            fork_key = (pr._metadata or {}).get('full_name', pr.author.github)
+            if isinstance(rmt, remote.GitHub) and fork_key:
+                target = '{}:{}'.format(fork_key, pr.head)
             else:
                 target = pr.head
             log.info("Found associated branch '{}' for '{}'".format(target, pr))
+        elif args.remote:
+            sys.stderr.write('Caller specified --remote, but argument was not a pull request.')
+            return 1
 
         try:
             commit = repository.checkout(target)

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py (293475 => 293476)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py	2022-04-26 22:33:08 UTC (rev 293475)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py	2022-04-26 22:36:52 UTC (rev 293476)
@@ -62,6 +62,7 @@
                 generator=self,
                 metadata=dict(
                     issue=self.repository.tracker.from_string(issue_ref) if issue_ref else None,
+                    full_name=data.get('head', {}).get('repo', {}).get('full_name')
                 ), url=''.format(self.repository.url, data['number']),
                 draft=data['draft'],
             )
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to