Diff
Modified: trunk/Tools/ChangeLog (287114 => 287115)
--- trunk/Tools/ChangeLog 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/ChangeLog 2021-12-16 00:51:44 UTC (rev 287115)
@@ -1,3 +1,36 @@
+2021-12-15 Jonathan Bedard <jbed...@apple.com>
+
+ [reporelaypy] Forward branches to alternate remote
+ https://bugs.webkit.org/show_bug.cgi?id=234347
+ <rdar://problem/86526293>
+
+ Reviewed by Dewei Zhu.
+
+ * Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version.
+ * Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
+ (Checkout.Encoder.default): Add remotes.
+ (Checkout.clone): After cloning a repository, add required remotes.
+ (Checkout.add_remotes): Track remotes in repository.
+ (Checkout.__init__): Allow caller to specify set of remotes to be tracked.
+ (Checkout.push_update): Push update for specified remote.
+ (Checkout.update_for): Return 'True' and 'False.'
+ (Checkout.update_all): If a branch is being updated, we should forward that
+ update to any tracked remotes.
+ * Scripts/libraries/reporelaypy/reporelaypy/hooks.py:
+ (HookProcessor.process_worker_hook): After updating a branch, forward that
+ update to any tracked remotes.
+ * Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py:
+ (CheckoutUnittest.test_constructor_no_sentinal): Capture debug logging.
+ * Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py:
+ (CheckoutRouteUnittest.test_landing): Capture debug logging.
+ (CheckoutRouteUnittest.test_invoked_redirect): Ditto.
+ (CheckoutRouteUnittest.test_trac): Ditto.
+ * Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py:
+ (HooksUnittest.test_process): Test for any error logging.
+ (HooksUnittest.test_process_branch): Ditto.
+ * Scripts/libraries/reporelaypy/run: Allow caller to specify remote to be tracked.
+ * Scripts/libraries/reporelaypy/setup.py: Bump version.
+
2021-12-15 Don Olmstead <don.olmst...@sony.com>
Split ATK specific code in WPEViewBackends
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -44,7 +44,7 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(0, 3, 1)
+version = Version(0, 4, 0)
import webkitflaskpy
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -47,6 +47,7 @@
path=obj.path,
url=""
sentinal=obj.sentinal,
+ remotes=obj.remotes,
)
if obj.fallback_repository:
result['fallback_url'] = obj.fallback_repository.url
@@ -60,19 +61,27 @@
return cls(**data, primary=False)
@staticmethod
- def clone(url, path, sentinal_file=None):
+ def clone(url, path, remotes, sentinal_file=None):
run([local.Git.executable(), 'clone', url, path], cwd=os.path.dirname(path))
run([local.Git.executable(), 'config', 'pull.ff', 'only'], cwd=path)
+ Checkout.add_remotes(local.Git(path), remotes)
+
if sentinal_file:
with open(sentinal_file, 'w') as cloned:
cloned.write('yes\n')
return 0
- def __init__(self, path, url="" http_proxy=None, sentinal=True, fallback_url=None, primary=True):
+ @staticmethod
+ def add_remotes(repository, remotes):
+ for name, url in (remotes or {}).items():
+ run([repository.executable(), 'remote', 'add', name, url], cwd=repository.root_path)
+
+ def __init__(self, path, url="" http_proxy=None, sentinal=True, fallback_url=None, primary=True, remotes=None):
self.sentinal = sentinal
self.path = path
self.url = ""
+ self.remotes = remotes or dict()
self._repository = None
self._child_process = None
self.fallback_repository = remote.Scm.from_url(fallback_url) if fallback_url else None
@@ -99,6 +108,8 @@
sys.stderr.write("Specified '{}' as the URL, but the specified path is from '{}'\n".format(
self.url, self.repository.url(name='origin'),
))
+ if primary:
+ Checkout.add_remotes(self.repository, remotes)
return
except FileNotFoundError:
pass
@@ -117,11 +128,11 @@
if self.sentinal:
self._child_process = multiprocessing.Process(
target=self.clone,
- args=(self.url, path, self.sentinal_file),
+ args=(self.url, path, self.remotes, self.sentinal_file),
)
self._child_process.start()
else:
- self.clone(self.url, path)
+ self.clone(self.url, path, self.remotes)
@property
def sentinal_file(self):
@@ -164,10 +175,23 @@
return ref == line.split()[0]
return False
+ def push_update(self, branch=None, remote=None, track=False):
+ if not remote or remote in ('origin', 'fork'):
+ return False
+
+ branch = branch or self.repository.default_branch
+ if not track and self.is_updated(branch, remote=remote):
+ return False
+
+ return not run(
+ [self.repository.executable(), 'push', remote, branch, '-f'],
+ cwd=self.repository.root_path,
+ ).returncode
+
def update_for(self, branch=None, remote='origin', track=False):
if not self.repository:
sys.stderr.write("Cannot update '{}', clone still pending...\n".format(branch))
- return None
+ return False
branch = branch or self.repository.default_branch
if branch == self.repository.default_branch:
@@ -177,6 +201,7 @@
elif not self.repository.prod_branches.match(branch):
return False
elif track and branch not in self.repository.branches_for(remote=remote):
+ run([self.repository.executable(), 'fetch'], cwd=self.repository.root_path)
run(
[self.repository.executable(), 'branch', '--track', branch, 'remotes/{}/{}'.format(remote, branch)],
cwd=self.repository.root_path,
@@ -206,6 +231,7 @@
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()]
# Then, track all untracked branches
for branch in all_branches:
@@ -213,4 +239,5 @@
[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.repository.cache.populate(branch=branch)
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -23,6 +23,7 @@
import hashlib
import hmac
import json
+import sys
from flask import current_app, json as fjson, request
from reporelaypy import Database
@@ -66,6 +67,7 @@
if branch.startswith('refs/heads/'):
branch = branch[len('refs/heads/'):]
self.checkout.update_for(branch, track=True)
+ [self.checkout.push_update(branch=branch, remote=remote, track=True) for remote in self.checkout.remotes.keys()]
except BaseException as e:
sys.stderr.write('{}\n'.format(e))
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -42,7 +42,7 @@
Checkout(path=self.path, url="" sentinal=True)
def test_constructor_no_sentinal(self):
- with mocks.local.Git(self.path) as repo:
+ with mocks.local.Git(self.path) as repo, OutputCapture():
Checkout(path=self.path, url="" sentinal=False)
with self.assertRaises(Checkout.Exception):
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -107,7 +107,7 @@
@mock_app
def test_landing(self, app=None, client=None):
- with mocks.local.Git(self.path) as repo:
+ with mocks.local.Git(self.path) as repo, OutputCapture():
app.register_blueprint(CheckoutRoute(
Checkout(path=self.path, url="" sentinal=False),
redirectors=[Redirector('https://trac.webkit.org')],
@@ -147,7 +147,7 @@
@mock_app
def test_invoked_redirect(self, app=None, client=None):
- with mocks.local.Git(self.path, git_svn=True) as repo:
+ with mocks.local.Git(self.path, git_svn=True) as repo, OutputCapture():
app.register_blueprint(CheckoutRoute(
Checkout(path=self.path, url="" sentinal=False),
redirectors=[Redirector('https://github.com/WebKit/WebKit'), Redirector('https://trac.webkit.org')],
@@ -162,7 +162,7 @@
@mock_app
def test_trac(self, app=None, client=None):
- with mocks.local.Git(self.path, git_svn=True) as repo:
+ with mocks.local.Git(self.path, git_svn=True) as repo, OutputCapture():
app.register_blueprint(CheckoutRoute(
Checkout(path=self.path, url="" sentinal=False),
redirectors=[Redirector('https://github.com/WebKit/WebKit')],
Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -71,7 +71,7 @@
@mock_app
def test_process(self, app=None, client=None):
- with OutputCapture(), mocks.local.Git(self.path) as repo:
+ with OutputCapture() as captured, mocks.local.Git(self.path) as repo:
database = Database()
app.register_blueprint(HookReceiver(database=database, debug=True))
@@ -88,9 +88,11 @@
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
+ self.assertEqual(captured.stderr.getvalue(), '')
+
@mock_app
def test_process_branch(self, app=None, client=None):
- with OutputCapture(), mocks.local.Git(self.path) as repo:
+ with OutputCapture() as captured, mocks.local.Git(self.path) as repo:
database = Database()
app.register_blueprint(HookReceiver(database=database, debug=True))
@@ -107,6 +109,8 @@
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
+ self.assertEqual(captured.stderr.getvalue(), '')
+
@mock_app
def test_hmac(self, app=None, client=None):
app.register_blueprint(HookReceiver(debug=True, secret='secret'))
Modified: trunk/Tools/Scripts/libraries/reporelaypy/run (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/run 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/run 2021-12-16 00:51:44 UTC (rev 287115)
@@ -72,6 +72,10 @@
'--fallback', dest='fallback', default=None, action='', type=str,
help='Fallback repository URL',
)
+ group.add_argument(
+ '--remote', dest='remotes', action='',
+ help="Add an additional remote to forward changes to, formatted as 'name:url'",
+ )
group = parser.add_argument_group('Database')
group.add_argument(
@@ -124,6 +128,14 @@
database.ping()
print('Connected to database!')
+ remotes = {}
+ for pair in args.remotes:
+ name, remote = pair.split(':', 1)
+ if not remote:
+ sys.stderr("Invalid forwarding remote '{}'".format(pair))
+ return 1
+ remotes[name] = remote
+
print('Finding checkout...')
checkout = Checkout(
path=args.path,
@@ -131,6 +143,7 @@
http_proxy=args.http_proxy,
sentinal=args.sentinal,
fallback_url=args.fallback,
+ remotes=remotes,
)
print('Git checkout:')
print(' Path: {}'.format(checkout.path))
@@ -143,6 +156,10 @@
if args.update_interval:
print(' Polling checkout with interval of {} seconds, doing first poll now...'.format(args.update_interval))
checkout.update_all()
+ if remotes:
+ print('Forwarding updates to:')
+ for name, url in remotes.items():
+ print(' {}: {}'.format(name, url))
if args.redirector:
print('User specified the following redirect urls:')
Modified: trunk/Tools/Scripts/libraries/reporelaypy/setup.py (287114 => 287115)
--- trunk/Tools/Scripts/libraries/reporelaypy/setup.py 2021-12-16 00:46:40 UTC (rev 287114)
+++ trunk/Tools/Scripts/libraries/reporelaypy/setup.py 2021-12-16 00:51:44 UTC (rev 287115)
@@ -30,7 +30,7 @@
setup(
name='reporelaypy',
- version='0.3.1',
+ version='0.4.0',
description='Library for visualizing, processing and storing test results.',
long_description=readme(),
classifiers=[