gitlab - Add support for depends-on dependency
Change-Id: I388677ebcec98158672744c91f7dd441bffb9511
This commit is contained in:
parent
d8d48457fd
commit
ef3fc335ed
|
@ -1698,8 +1698,7 @@ class FakeGitlabMergeRequest(object):
|
|||
self.labels = []
|
||||
self.notes = []
|
||||
self.url = "https://%s/%s/merge_requests/%s" % (
|
||||
self.gitlab.server, urllib.parse.quote_plus(
|
||||
self.project), self.number)
|
||||
self.gitlab.server, self.project, self.number)
|
||||
self.is_merged = False
|
||||
self.mr_ref = self._createMRRef()
|
||||
self._addCommitInMR(files=files)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
- pipeline:
|
||||
name: check
|
||||
manager: independent
|
||||
trigger:
|
||||
gitlab:
|
||||
- event: gl_merge_request
|
||||
action: opened
|
||||
|
||||
- job:
|
||||
name: base
|
||||
parent: null
|
||||
run: playbooks/base.yaml
|
||||
|
||||
- job:
|
||||
name: project1-test
|
||||
run: playbooks/project1-test.yaml
|
||||
|
||||
- job:
|
||||
name: project2-test
|
||||
run: playbooks/project2-test.yaml
|
||||
|
||||
- project:
|
||||
name: org/project1
|
||||
check:
|
||||
jobs:
|
||||
- project1-test
|
||||
|
||||
- project:
|
||||
name: org/project2
|
||||
check:
|
||||
jobs:
|
||||
- project2-test
|
|
@ -404,3 +404,33 @@ class TestGitlabDriver(ZuulTestCase):
|
|||
self.assertEqual(self.getJobFromHistory('project-post-job').result,
|
||||
'SUCCESS')
|
||||
self.assertEqual(r, True)
|
||||
|
||||
@simple_layout('layouts/crd-gitlab.yaml', driver='gitlab')
|
||||
def test_crd_independent(self):
|
||||
|
||||
# Create a change in project1 that a project2 change will depend on
|
||||
A = self.fake_gitlab.openFakeMergeRequest(
|
||||
'org/project1', 'master', 'A')
|
||||
|
||||
# Create a commit in B that sets the dependency on A
|
||||
msg = "Depends-On: %s" % A.url
|
||||
B = self.fake_gitlab.openFakeMergeRequest(
|
||||
'org/project2', 'master', 'B', description=msg)
|
||||
|
||||
# Make an event to re-use
|
||||
self.fake_gitlab.emitEvent(B.getMergeRequestOpenedEvent())
|
||||
self.waitUntilSettled()
|
||||
|
||||
# The changes for the job from project2 should include the project1
|
||||
# PR content
|
||||
changes = self.getJobFromHistory(
|
||||
'project2-test', 'org/project2').changes
|
||||
|
||||
self.assertEqual(changes, "%s,%s %s,%s" % (A.number,
|
||||
A.sha,
|
||||
B.number,
|
||||
B.sha))
|
||||
|
||||
# There should be no more changes in the queue
|
||||
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
|
||||
self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import re
|
||||
import logging
|
||||
import urllib
|
||||
|
||||
from zuul.model import Project
|
||||
from zuul.source import BaseSource
|
||||
|
@ -28,6 +30,7 @@ class GitlabSource(BaseSource):
|
|||
hostname = connection.canonical_hostname
|
||||
super(GitlabSource, self).__init__(driver, connection,
|
||||
hostname, config)
|
||||
self.change_re = re.compile(r"/(.*?)/(?:-/)?merge_requests/(\d+)")
|
||||
|
||||
def getRefSha(self, project, ref):
|
||||
"""Return a sha for a given project ref."""
|
||||
|
@ -53,7 +56,27 @@ class GitlabSource(BaseSource):
|
|||
return self.connection.getChange(event, refresh)
|
||||
|
||||
def getChangeByURL(self, url):
|
||||
raise NotImplementedError()
|
||||
try:
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
except ValueError:
|
||||
return None
|
||||
m = self.change_re.match(parsed.path)
|
||||
if not m:
|
||||
return None
|
||||
project_name = m.group(1)
|
||||
try:
|
||||
num = int(m.group(2))
|
||||
except ValueError:
|
||||
return None
|
||||
mr = self.connection.getPull(project_name, num)
|
||||
if not mr:
|
||||
return None
|
||||
project = self.getProject(project_name)
|
||||
change = self.connection._getChange(
|
||||
project, num,
|
||||
patchset=mr['sha'],
|
||||
url=url)
|
||||
return change
|
||||
|
||||
def getChangesDependingOn(self, change, projects, tenant):
|
||||
raise NotImplementedError()
|
||||
|
|
Loading…
Reference in New Issue