Skip to content
Permalink
Browse files
[commits.webkit.org] Support compare redirect
https://bugs.webkit.org/show_bug.cgi?id=240908
<rdar://problem/93904385>

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/checkoutroute.py:
(Redirector):
(Redirector.bitbucket_compare): Added.
(Redirector.trac_compare): Added.
(Redirector.github_compare): Added.
(Redirector.__init__): Define a compare function.
(CheckoutRoute):
(CheckoutRoute.find_newer): Add function to sort a commit pair.
(CheckoutRoute.__init__): Add 'compare' endpoints.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py:
(CheckoutRouteUnittest.test_compare):
(CheckoutRouteUnittest.test_compare_trac):

Canonical link: https://commits.webkit.org/250999@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294869 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 26, 2022
1 parent 06b95d5 commit 427a54276531e38272eb70133e1ad05bc07156ed
Showing 4 changed files with 82 additions and 7 deletions.
@@ -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, 6, 0)
version = Version(0, 7, 0)

import webkitflaskpy

@@ -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
@@ -53,6 +53,15 @@ def redirector(commit):

return redirector

@classmethod
def bitbucket_compare(cls, url):
def redirector(head, base):
if head and head.hash and base and base.hash:
return redirect('{}/compare/diff?targetBranch={}&sourceBranch={}'.format(url, base.hash, head.hash))
return redirect('{}/compare'.format(url))

return redirector

@classmethod
def trac_generator(cls, base):
def redirector(commit):
@@ -62,6 +71,15 @@ def redirector(commit):

return redirector

@classmethod
def trac_compare(cls, url):
def redirector(head, base):
if head and head.revision and base and base.revision:
return redirect('{}/log/webkit/trunk?verbose=on&rev={}&stop_rev={}'.format(url, head.revision, base.revision))
return redirect('{}/log/webkit/trunk'.format(url))

return redirector

@classmethod
def github_generator(cls, base):
def redirector(commit):
@@ -71,6 +89,15 @@ def redirector(commit):

return redirector

@classmethod
def github_compare(cls, url):
def redirector(head, base):
if head and head.hash and base and base.hash:
return redirect('{}/compare/{}...{}'.format(url, base.hash, head.hash))
return redirect('{}/compare'.format(url))

return redirector

@classmethod
def from_json(cls, data):
data = data if isinstance(data, dict) else json.loads(data)
@@ -84,14 +111,15 @@ def __init__(self, url, name=None):
self._redirect = None

for key, params in dict(
bitbucket=(remote.BitBucket.URL_RE, self.bitbucket_generator),
trac=(re.compile(r'\Ahttps?://trac.(?P<domain>\S+)\Z'), self.trac_generator),
github=(remote.GitHub.URL_RE, self.github_generator),
bitbucket=(remote.BitBucket.URL_RE, self.bitbucket_generator, self.bitbucket_compare),
trac=(re.compile(r'\Ahttps?://trac.(?P<domain>\S+)\Z'), self.trac_generator, self.trac_compare),
github=(remote.GitHub.URL_RE, self.github_generator, self.github_compare),
).items():
regex, generator = params
regex, generator, compare = params
if regex.match(url):
self.type = key
self._redirect = generator(url)
self.compare = compare(url)
break
if not self.type:
raise TypeError("'{}' is not a recognized redirect base")
@@ -104,6 +132,14 @@ def __call__(self, commit):


class CheckoutRoute(AuthedBlueprint):
@classmethod
def find_newer(cls, a, b):
if not a or not b:
return a, b
if a.uuid < b.uuid:
return b, a
return a, b

def __init__(self, checkout, redirectors=None, import_name=__name__, auth_decorator=None, database=None):
super(CheckoutRoute, self).__init__('checkout', import_name, url_prefix=None, auth_decorator=auth_decorator)

@@ -120,6 +156,11 @@ def __init__(self, checkout, redirectors=None, import_name=__name__, auth_decora
lambda ref: self.redirectors[0](self.commit(ref)),
methods=('GET',),
)
self.add_url_rule(
'/compare/<path:head>...<path:base>', 'compare',
lambda head, base: self.redirectors[0].compare(*self.find_newer(self.commit(head), self.commit(base))), methods=('GET',),
)

for redirector in self.redirectors:
self.add_url_rule(
'/{}'.format(redirector.name), 'landing-{}'.format(redirector.name),
@@ -130,6 +171,10 @@ def __init__(self, checkout, redirectors=None, import_name=__name__, auth_decora
'/<path:ref>/{}'.format(redirector.name), 'redirect-{}'.format(redirector.name),
lambda ref, redirector=redirector: redirector(self.commit(ref)), methods=('GET',),
)
self.add_url_rule(
'/compare/<path:head>...<path:base>/{}'.format(redirector.name), 'compare-{}'.format(redirector.name),
lambda head, base, redirector=redirector: redirector.compare(*self.find_newer(self.commit(head), self.commit(base))), methods=('GET',),
)

self.add_url_rule('/<path:ref>/json', 'api', self.api, methods=('GET',))
self.add_url_rule('/changeset/<path:revision>/webkit', 'trac', self.trac, methods=('GET',))
@@ -174,3 +174,33 @@ def test_trac(self, app=None, client=None):
response.headers.get('location'),
'https://github.com/WebKit/WebKit/commit/621652add7fc416099bd2063366cc38ff61afe36',
)

@mock_app
def test_compare(self, app=None, client=None):
with mocks.local.Git(self.path) as repo:
app.register_blueprint(CheckoutRoute(
Checkout(path=self.path, url=repo.remote, sentinal=False),
redirectors=[Redirector('https://github.com/WebKit/WebKit')],
))

response = client.get('compare/2@main...4@main')
self.assertEqual(response.status_code, 302)
self.assertEqual(
response.headers.get('location'),
'https://github.com/WebKit/WebKit/compare/fff83bb2d9171b4d9196e977eb0508fd57e7a08d...bae5d1e90999d4f916a8a15810ccfa43f37a2fd6',
)

@mock_app
def test_compare_trac(self, app=None, client=None):
with mocks.local.Git(self.path) as repo:
app.register_blueprint(CheckoutRoute(
Checkout(path=self.path, url=repo.remote, sentinal=False),
redirectors=[Redirector('https://github.com/WebKit/WebKit'), Redirector('https://trac.webkit.org')],
))

response = client.get('compare/2@main...4@main')
self.assertEqual(response.status_code, 302)
self.assertEqual(
response.headers.get('location'),
'https://github.com/WebKit/WebKit/compare/fff83bb2d9171b4d9196e977eb0508fd57e7a08d...bae5d1e90999d4f916a8a15810ccfa43f37a2fd6',
)
@@ -30,7 +30,7 @@ def readme():

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

0 comments on commit 427a542

Please sign in to comment.