Handle WIP Gerrit status

Newer versions of Gerrit have a built-in work-in-progress flag
which, when set, makes the change unsubmittable.  Update the
canMerge method in the Gerrit driver to recognize the new flag.

Change-Id: Ia8e5e50086933215c45e92b419a04c1117880a34
This commit is contained in:
James E. Blair 2021-01-05 15:01:16 -08:00
parent f093368280
commit 35e8736f11
4 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,6 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P.
# Copyright 2016 Red Hat, Inc.
# Copyright 2021 Acme Gating, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -638,6 +639,14 @@ class FakeGerritChange(object):
self.data['submitRecords'] = self.getSubmitRecords()
return json.loads(json.dumps(event))
def setWorkInProgress(self, wip):
# Gerrit only includes 'wip' in the data returned via ssh if
# the value is true.
if wip:
self.data['wip'] = True
elif 'wip' in self.data:
del self.data['wip']
def getSubmitRecords(self):
status = {}
for cat in self.categories:
@ -770,7 +779,8 @@ class FakeGerritChange(object):
"labels": labels,
"current_revision": self.patchsets[-1]['revision'],
"revisions": revisions,
"requirements": []
"requirements": [],
"work_in_progresss": self.data.get('wip', False)
}
return json.loads(json.dumps(data))

View File

@ -1249,6 +1249,10 @@ class TestScheduler(ZuulTestCase):
a = source.getChange(event, refresh=True)
self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
A.setWorkInProgress(True)
a = source.getChange(event, refresh=True)
self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
def test_project_merge_conflict(self):
"Test that gate merge conflicts are handled properly"

View File

@ -966,6 +966,8 @@ class GerritConnection(BaseConnection):
# Good question. It's probably ref-updated, which, ah,
# means it's merged.
return True
if change.wip:
return False
if change.missing_labels <= set(allow_needs):
return True
return False

View File

@ -32,6 +32,7 @@ class GerritChange(Change):
def __init__(self, project):
super(GerritChange, self).__init__(project)
self.status = None
self.wip = None
self.approvals = []
def update(self, data, connection):
@ -79,6 +80,7 @@ class GerritChange(Change):
self.approvals = data['currentPatchSet'].get('approvals', [])
self.open = data['open']
self.status = data['status']
self.wip = data.get('wip', False)
self.owner = data['owner'].get('username')
self.message = data['commitMessage']
@ -149,6 +151,7 @@ class GerritChange(Change):
self.missing_labels.add(label_name)
self.open = data['status'] == 'NEW'
self.status = data['status']
self.wip = data.get('work_in_progress', False)
self.owner = data['owner'].get('username')
self.message = current_revision['commit']['message']