Merge "gitlab - add missing handling of closed merge request"

This commit is contained in:
Zuul 2024-06-14 09:07:55 +00:00 committed by Gerrit Code Review
commit b0f080e7b7
5 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,3 @@
---
features:
- gitlab driver now handles the merge request 'close' action.

View File

@ -606,6 +606,9 @@ class FakeGitlabMergeRequest(object):
def getMergeRequestOpenedEvent(self):
return self.getMergeRequestEvent(action='open')
def getMergeRequestClosedEvent(self):
return self.getMergeRequestEvent(action='close')
def getMergeRequestUpdatedEvent(self):
self.addCommit()
return self.getMergeRequestEvent(action='update',

View File

@ -323,6 +323,23 @@ class TestGitlabDriver(ZuulTestCase):
], ordered=False
)
@simple_layout('layouts/basic-gitlab.yaml', driver='gitlab')
def test_dequeue_mr_abandoned(self):
self.executor_server.hold_jobs_in_build = True
A = self.fake_gitlab.openFakeMergeRequest('org/project', 'master', 'A')
self.fake_gitlab.emitEvent(A.getMergeRequestOpenedEvent())
self.waitUntilSettled()
self.fake_gitlab.emitEvent(A.getMergeRequestClosedEvent())
self.waitUntilSettled()
self.executor_server.hold_jobs_in_build = False
self.executor_server.release()
self.waitUntilSettled()
self.assertEqual(2, len(self.history))
self.assertEqual(2, self.countJobResults(self.history, 'ABORTED'))
@simple_layout('layouts/basic-gitlab.yaml', driver='gitlab')
def test_merge_request_commented(self):

View File

@ -151,6 +151,8 @@ class GitlabEventConnector(threading.Thread):
event.change_number)
if attrs['action'] == 'open':
event.action = 'opened'
elif attrs['action'] == 'close':
event.action = 'closed'
elif attrs['action'] == 'merge':
event.action = 'merged'
elif attrs['action'] == 'update' and attrs.get("oldrev"):

View File

@ -149,6 +149,11 @@ class GitlabTriggerEvent(TriggerEvent):
def isMessageChanged(self):
return bool(self.merge_request_description_changed)
def isChangeAbandoned(self):
if self.type == 'gl_merge_request':
return 'closed' == self.action
return False
class GitlabEventFilter(EventFilter):
def __init__(