Browse Source

Merge "Add support for Gerrit v2.16's change URL schema"

tags/3.3.1
Zuul 5 months ago
parent
commit
be4dc6e9d2
2 changed files with 19 additions and 5 deletions
  1. 18
    4
      tests/unit/test_gerrit_crd.py
  2. 1
    1
      zuul/driver/gerrit/gerritsource.py

+ 18
- 4
tests/unit/test_gerrit_crd.py View File

@@ -22,7 +22,7 @@ from tests.base import (
22 22
 class TestGerritCRD(ZuulTestCase):
23 23
     tenant_config_file = 'config/single-tenant/main.yaml'
24 24
 
25
-    def test_crd_gate(self):
25
+    def _test_crd_gate(self, url_fmt):
26 26
         "Test cross-repo dependencies"
27 27
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
28 28
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
@@ -52,9 +52,9 @@ class TestGerritCRD(ZuulTestCase):
52 52
         A.setDependsOn(AM1, 1)
53 53
         AM1.setDependsOn(AM2, 1)
54 54
 
55
-        # So that at least one test uses the /#/c/ form of the url,
56
-        # use it here.
57
-        url = 'https://%s/#/c/%s' % (B.gerrit.server, B.number)
55
+        url = url_fmt.format(baseurl=B.gerrit.baseurl.rstrip('/'),
56
+                             project=B.project,
57
+                             change_no=B.number)
58 58
         A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
59 59
             A.subject, url)
60 60
 
@@ -91,6 +91,20 @@ class TestGerritCRD(ZuulTestCase):
91 91
             'project-merge', 'org/project1').changes
92 92
         self.assertEqual(changes, '2,1 1,1')
93 93
 
94
+    # Different versions of Gerrit have used 3 different URL schemata for
95
+    # changes - repeat the simple test on each of the 3 to ensure they can be
96
+    # parsed, the other tests just use the default URL schema provided in
97
+    # FakeGerritChange.data['url'] .
98
+
99
+    def test_crd_gate_url_schema1(self):
100
+        self._test_crd_gate('{baseurl}/{change_no}')
101
+
102
+    def test_crd_gate_url_schema2(self):
103
+        self._test_crd_gate('{baseurl}/#/c/{change_no}')
104
+
105
+    def test_crd_gate_url_schema3(self):
106
+        self._test_crd_gate('{baseurl}/c/{project}/+/{change_no}/')
107
+
94 108
     def test_crd_gate_triangle(self):
95 109
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
96 110
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')

+ 1
- 1
zuul/driver/gerrit/gerritsource.py View File

@@ -38,7 +38,7 @@ class GerritSource(BaseSource):
38 38
             prefix_ui += '/'
39 39
 
40 40
         self.change_re = re.compile(
41
-            r"/%s(\#\/c\/)?(\d+)[\w]*" % prefix_ui)
41
+            r"/%s(\#\/c\/|c\/.*\/\+\/)?(\d+)[\w]*" % prefix_ui)
42 42
 
43 43
     def getRefSha(self, project, ref):
44 44
         return self.connection.getRefSha(project, ref)

Loading…
Cancel
Save