Skip to content
Permalink
Browse files
[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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293476 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Apr 26, 2022
1 parent 0975a44 commit a41010d1870238f2658e1478c6aa66f4219d103f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
@@ -1,3 +1,22 @@
2022-04-26 Jonathan Bedard <jbedard@apple.com>

[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 <jbedard@apple.com>

[build.webkit.org] Support identifiers in popover
@@ -29,7 +29,7 @@ def readme():

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=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"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)))
@@ -301,7 +301,7 @@ def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
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 @@ def checkout(self, argument):
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 = self.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()

@@ -41,6 +41,10 @@ def parser(cls, parser, loggers=None):
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 @@ def main(cls, args, repository, **kwargs):
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 @@ def main(cls, args, repository, **kwargs):
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)
@@ -62,6 +62,7 @@ def PullRequest(self, data):
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='{}/pull/{}'.format(self.repository.url, data['number']),
draft=data['draft'],
)

0 comments on commit a41010d

Please sign in to comment.