gerritdriver: enable triggering on wip state

Change-Id: I0358608cb588000f6f9c0ec8ac0c4db179f8fab7
This commit is contained in:
Albin Vass 2022-03-04 13:40:15 +01:00
parent 3f594f0721
commit f37531109e
9 changed files with 75 additions and 17 deletions

View File

@ -350,6 +350,11 @@ order to be enqueued into the pipeline.
A boolean value (``true`` or ``false``) that indicates whether the
change must be the current patchset in order to be enqueued.
.. attr:: wip
A boolean value (``true`` or ``false``) that indicates whether the
change must be wip or not wip in order to be enqueued.
.. attr:: status
A string value that corresponds with the status of the change

View File

@ -0,0 +1,5 @@
---
features:
- |
Pipelines can now trigger on ``wip-state-changed`` and filter events on the
wip state of a change with :attr:`pipeline.require.<gerrit source>.wip`.

View File

@ -49,6 +49,23 @@
gerrit:
Verified: -1
- pipeline:
name: wip-check
manager: independent
require:
gerrit:
wip: false
trigger:
gerrit:
- event: patchset-created
- event: comment-added
success:
gerrit:
Verified: 1
failure:
gerrit:
Verified: -1
- job:
name: base
parent: null
@ -74,3 +91,9 @@
status-check:
jobs:
- project-job
- project:
name: wip-project
wip-check:
jobs:
- project-job

View File

@ -0,0 +1 @@
test

View File

@ -8,3 +8,4 @@
- current-project
- open-project
- status-project
- wip-project

View File

@ -309,6 +309,18 @@ class TestRequirementsState(ZuulTestCase):
self.waitUntilSettled()
self.assertEqual(len(self.history), 1)
def test_pipeline_require_wip(self):
A = self.fake_gerrit.addFakeChange('wip-project', 'master', 'A')
A.setWorkInProgress(True)
self.fake_gerrit.addEvent(A.addApproval('Code-Review', 2))
self.waitUntilSettled()
self.assertEqual(len(self.history), 0)
B = self.fake_gerrit.addFakeChange('wip-project', 'master', 'B')
self.fake_gerrit.addEvent(B.addApproval('Code-Review', 2))
self.waitUntilSettled()
self.assertEqual(len(self.history), 1)
class TestRequirementsRejectUsername(ZuulTestCase):
"""Requirements with reject username requirement"""

View File

@ -491,7 +491,7 @@ class GerritEventFilter(EventFilter, GerritApprovalFilter):
class GerritRefFilter(RefFilter, GerritApprovalFilter):
def __init__(self, connection_name, open=None, current_patchset=None,
statuses=[], required_approvals=[],
wip=None, statuses=[], required_approvals=[],
reject_approvals=[]):
RefFilter.__init__(self, connection_name)
@ -500,6 +500,7 @@ class GerritRefFilter(RefFilter, GerritApprovalFilter):
reject_approvals=reject_approvals)
self.open = open
self.wip = wip
self.current_patchset = current_patchset
self.statuses = statuses
@ -524,23 +525,30 @@ class GerritRefFilter(RefFilter, GerritApprovalFilter):
return ret
def matches(self, change):
if self.open is not None:
# if a "change" has no number, it's not a change, but a push
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if self.open != change.open:
return False
else:
return False
if self.current_patchset is not None:
# if a "change" has no number, it's not a change, but a push
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if self.current_patchset != change.is_current_patchset:
return False
else:
filters = [
{
"required": self.open,
"value": change.open
},
{
"required": self.current_patchset,
"value": change.is_current_patchset
},
{
"required": self.wip,
"value": change.wip
},
]
configured = filter(lambda x: x["required"] is not None, filters)
# if a "change" has no number, it's not a change, but a push
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if any(map(lambda x: x["required"] != x["value"], configured)):
return False
elif configured:
return False
if self.statuses:
if change.status not in self.statuses:

View File

@ -203,6 +203,7 @@ class GerritSource(BaseSource):
connection_name=self.connection.connection_name,
open=config.get('open'),
current_patchset=config.get('current-patchset'),
wip=config.get('wip'),
statuses=to_list(config.get('status')),
required_approvals=to_list(config.get('approval')),
)
@ -234,6 +235,7 @@ def getRequireSchema():
require = {'approval': scalar_or_list(approval),
'open': bool,
'current-patchset': bool,
'wip': bool,
'status': scalar_or_list(str)}
return require

View File

@ -85,7 +85,8 @@ def getSchema():
'comment-added',
'ref-updated',
'pending-check',
'vote-deleted')),
'vote-deleted',
'wip-state-changed')),
'uuid': str,
'scheme': str,
'comment_filter': scalar_or_list(str),