Title: [294869] trunk/Tools/Scripts/libraries/reporelaypy
Revision
294869
Author
[email protected]
Date
2022-05-25 22:21:11 -0700 (Wed, 25 May 2022)

Log Message

[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

Modified Paths

Diff

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py (294868 => 294869)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py	2022-05-26 04:09:03 UTC (rev 294868)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py	2022-05-26 05:21:11 UTC (rev 294869)
@@ -44,7 +44,7 @@
         "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
 

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkoutroute.py (294868 => 294869)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkoutroute.py	2022-05-26 04:09:03 UTC (rev 294868)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkoutroute.py	2022-05-26 05:21:11 UTC (rev 294869)
@@ -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,15 @@
         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):
             if commit and commit.revision:
@@ -63,6 +72,15 @@
         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):
             if commit and commit.hash:
@@ -72,6 +90,15 @@
         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 = "" if isinstance(data, dict) else json.loads(data)
         if isinstance(data, list):
@@ -84,14 +111,15 @@
         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 @@
 
 
 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 @@
             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 @@
                 '/<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',))

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py (294868 => 294869)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py	2022-05-26 04:09:03 UTC (rev 294868)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkoutroute_unittest.py	2022-05-26 05:21:11 UTC (rev 294869)
@@ -174,3 +174,33 @@
                 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="" sentinal=False),
+                redirectors=[Redirector('https://github.com/WebKit/WebKit')],
+            ))
+
+            response = client.get('compare/[email protected]@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="" sentinal=False),
+                redirectors=[Redirector('https://github.com/WebKit/WebKit'), Redirector('https://trac.webkit.org')],
+            ))
+
+            response = client.get('compare/[email protected]@main')
+            self.assertEqual(response.status_code, 302)
+            self.assertEqual(
+                response.headers.get('location'),
+                'https://github.com/WebKit/WebKit/compare/fff83bb2d9171b4d9196e977eb0508fd57e7a08d...bae5d1e90999d4f916a8a15810ccfa43f37a2fd6',
+            )

Modified: trunk/Tools/Scripts/libraries/reporelaypy/setup.py (294868 => 294869)


--- trunk/Tools/Scripts/libraries/reporelaypy/setup.py	2022-05-26 04:09:03 UTC (rev 294868)
+++ trunk/Tools/Scripts/libraries/reporelaypy/setup.py	2022-05-26 05:21:11 UTC (rev 294869)
@@ -30,7 +30,7 @@
 
 setup(
     name='reporelaypy',
-    version='0.6.0',
+    version='0.7.0',
     description='Library for visualizing, processing and storing test results.',
     long_description=readme(),
     classifiers=[
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to