Skip to content
Permalink
Browse files
[commits.webkit.org] Change branch forwarding behavior
https://bugs.webkit.org/show_bug.cgi?id=239136
<rdar://problem/91314217>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version.
* Tools/Scripts/libraries/reporelaypy/setup.py: Ditto.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
(Checkout.Encoder.default): Encode forwarding list.
(Checkout.__init__): Add forwarding argument.
(Checkout.push_update): Add dest_branch argument.
(Checkout.forward_update): Trigger push_update based on forwarding arguments.
(Checkout.update_all): Use forward_update instead of pushing to every branch.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py:
(HookProcessor.process_worker_hook): Extract remote from incoming data, invoke forward_update.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py:
(CheckoutUnittest.test_json):

Canonical link: https://commits.webkit.org/250045@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293514 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Apr 27, 2022
1 parent 1ab1c05 commit b191a692af26094da66405d0435bbc3ed88407fa
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
@@ -1,3 +1,24 @@
2022-04-27 Jonathan Bedard <jbedard@apple.com>

[commits.webkit.org] Change branch forwarding behavior
https://bugs.webkit.org/show_bug.cgi?id=239136
<rdar://problem/91314217>

Reviewed by Dewei Zhu.

* Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version.
* Scripts/libraries/reporelaypy/setup.py: Ditto.
* Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
(Checkout.Encoder.default): Encode forwarding list.
(Checkout.__init__): Add forwarding argument.
(Checkout.push_update): Add dest_branch argument.
(Checkout.forward_update): Trigger push_update based on forwarding arguments.
(Checkout.update_all): Use forward_update instead of pushing to every branch.
* Scripts/libraries/reporelaypy/reporelaypy/hooks.py:
(HookProcessor.process_worker_hook): Extract remote from incoming data, invoke forward_update.
* Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py:
(CheckoutUnittest.test_json):

2022-04-27 Kimmo Kinnunen <kkinnunen@apple.com>

test-webkitperl outputs git hints during the test
@@ -44,7 +44,7 @@ def _maybe_add_webkit_python_library_paths():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(0, 5, 2)
version = Version(0, 6, 0)

import webkitflaskpy

@@ -50,6 +50,7 @@ def default(self, obj):
url=obj.url,
sentinal=obj.sentinal,
remotes=obj.remotes,
forwarding=obj.forwarding,
credentials=obj.credentials,
)
if obj.fallback_repository:
@@ -104,11 +105,17 @@ def add_credentials(repository, credentials):
with open(os.path.expanduser('~/.git-credentials'), 'w') as f:
f.write(git_credentials_content)

def __init__(self, path, url=None, http_proxy=None, sentinal=True, fallback_url=None, primary=True, remotes=None, credentials=None):
def __init__(
self, path, url=None, http_proxy=None,
sentinal=True, fallback_url=None, primary=True,
remotes=None, credentials=None,
forwarding=None,
):
self.sentinal = sentinal
self.path = path
self.url = url
self.remotes = remotes or dict()
self.forwarding = forwarding or [('origin', list(self.remotes.keys()))]
self.credentials = credentials or dict()
self._repository = None
self._child_process = None
@@ -204,8 +211,8 @@ def is_updated(self, branch, remote=REMOTE):
return ref == line.split()[0]
return False

def push_update(self, branch=None, tag=None, remote=None, track=False):
if not remote or remote in (self.REMOTE, 'fork'):
def push_update(self, branch=None, tag=None, remote=None, track=False, dest_branch=None):
if not remote or remote in ('fork',):
return False

if tag:
@@ -219,10 +226,26 @@ def push_update(self, branch=None, tag=None, remote=None, track=False):
return False

return not run(
[self.repository.executable(), 'push', remote, branch, '-f'],
[self.repository.executable(), 'push', remote, '{}:{}'.format(branch, dest_branch or branch)],
cwd=self.repository.root_path,
).returncode

def forward_update(self, branch=None, tag=None, remote=None, track=False):
for match, tos in self.forwarding:
if match not in (remote, '{}:{}'.format(remote, branch or tag)):
continue
for to in tos:
split = to.split(':', 1)
self.push_update(
branch=branch,
tag=tag,
remote=split[0],
track=track,
dest_branch=split[1] if len(split) > 1 else None,
)
return
return

def fetch(self, remote=REMOTE):
return not run(
[self.repository.executable(), 'fetch', remote],
@@ -273,7 +296,7 @@ def update_all(self, remote=REMOTE):
if branch in all_branches:
all_branches.remove(branch)
self.update_for(branch=branch, remote=remote)
[self.push_update(branch=branch, remote=remote) for remote in self.remotes.keys()]
self.forward_update(branch=branch, remote=remote)

# Then, track all untracked branches
print('Tracking new branches...')
@@ -282,7 +305,7 @@ def update_all(self, remote=REMOTE):
[self.repository.executable(), 'branch', '--track', branch, 'remotes/{}/{}'.format(remote, branch)],
cwd=self.repository.root_path,
)
[self.push_update(branch=branch, remote=remote) for remote in self.remotes.keys()]
self.forward_update(branch=branch, remote=remote)
self.repository.cache.populate(branch=branch)

# Sync all tags
@@ -295,4 +318,4 @@ def update_all(self, remote=REMOTE):
remote_tags = set(self.repository.tags(remote=target_remote))
for tag in origin_tags - remote_tags:
print(f' {tag}')
self.push_update(tag=tag, remote=target_remote)
self.forward_update(tag=tag, remote=remote)
@@ -23,6 +23,7 @@
import hashlib
import hmac
import json
import re
import sys

from flask import current_app, json as fjson, request
@@ -39,6 +40,7 @@ class HookProcessor(object):
TYPES = ('pull_request', 'push')
BRANCH_PREFIX = 'refs/heads/'
TAG_PREFIX = 'refs/tags/'
REMOTES_RE = re.compile(r'remote\.(?P<remote>\S+)\.url')

@classmethod
def is_valid(cls, type, data):
@@ -68,17 +70,27 @@ def process_worker_hook(self, type, data):
return None

branch = data.get('ref')
remote = ''
name = data.get('repository', {}).get('url', '').split('://')[-1]
if name and self.checkout.repository:
for config_arg, url in self.checkout.repository.config().items():
match = self.REMOTES_RE.match(config_arg)
if not match or '{}.git'.format(name) not in [url.split('@')[-1], url.split('://')[-1]]:
continue
remote = match.group('remote')
break

if type == 'push' and branch:
try:
if branch.startswith(self.BRANCH_PREFIX):
branch = branch[len(self.BRANCH_PREFIX):]
self.checkout.update_for(branch, track=True)
[self.checkout.push_update(branch=branch, remote=remote, track=True) for remote in self.checkout.remotes.keys()]
self.checkout.forward_update(branch=branch, remote=remote, track=True)

if branch.startswith(self.TAG_PREFIX):
tag = branch[len(self.TAG_PREFIX):]
self.checkout.fetch()
[self.checkout.push_update(tag=tag, remote=remote) for remote in self.checkout.remotes.keys()]
self.checkout.forward_update(tag=tag, remote=remote)

except BaseException as e:
sys.stderr.write('{}\n'.format(e))
@@ -1,4 +1,4 @@
# Copyright (C) 2021 Apple Inc. All rights reserved.
# Copyright (C) 2021-2022 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -54,6 +54,7 @@ def test_json(self):
path=self.path,
url=repo.remote,
remotes={},
forwarding=[('origin', [])],
credentials={
'https://github.com': dict(
username='username',
@@ -30,7 +30,7 @@ def readme():

setup(
name='reporelaypy',
version='0.5.2',
version='0.6.0',
description='Library for visualizing, processing and storing test results.',
long_description=readme(),
classifiers=[

0 comments on commit b191a69

Please sign in to comment.