summaryrefslogtreecommitdiff
path: root/zuul/driver/github
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2022-10-10 10:53:14 -0700
committerJames E. Blair <jim@acmegating.com>2022-10-10 10:54:33 -0700
commit7aba198bedcf2080f26e2498f834002971175c33 (patch)
tree9586c69102e0a0022d2c4a4a5f14bc227d90ffcf /zuul/driver/github
parent51aeec13e682e2341d6c65379ef558bcb4d62ee0 (diff)
downloadzuul-7aba198bedcf2080f26e2498f834002971175c33.tar.gz
Add "draft" github pipeline requirement
This adds the "draft" PR status as a pipeline requirement to the GitHub driver. It is already used implicitly in dependent pipelines, but this will allow it to be added explicitly to other pipelines (for example, check). This also fixes some minor copy/pasta errors in debug messages related to github pipeline requirements. Change-Id: I05f8f61aee251af24c1479274904b429baedb29d
Diffstat (limited to 'zuul/driver/github')
-rw-r--r--zuul/driver/github/githubmodel.py42
-rw-r--r--zuul/driver/github/githubsource.py4
2 files changed, 35 insertions, 11 deletions
diff --git a/zuul/driver/github/githubmodel.py b/zuul/driver/github/githubmodel.py
index 5fa076316..256333234 100644
--- a/zuul/driver/github/githubmodel.py
+++ b/zuul/driver/github/githubmodel.py
@@ -455,11 +455,12 @@ class GithubEventFilter(EventFilter, GithubCommonFilter):
class GithubRefFilter(RefFilter, GithubCommonFilter):
- def __init__(self, connection_name, statuses=[], required_reviews=[],
- reject_reviews=[], open=None, merged=None,
- current_patchset=None, reject_open=None, reject_merged=None,
- reject_current_patchset=None, labels=[], reject_labels=[],
- reject_statuses=[]):
+ def __init__(self, connection_name, statuses=[],
+ required_reviews=[], reject_reviews=[], open=None,
+ merged=None, current_patchset=None, draft=None,
+ reject_open=None, reject_merged=None,
+ reject_current_patchset=None, reject_draft=None,
+ labels=[], reject_labels=[], reject_statuses=[]):
RefFilter.__init__(self, connection_name)
GithubCommonFilter.__init__(self, required_reviews=required_reviews,
@@ -479,6 +480,10 @@ class GithubRefFilter(RefFilter, GithubCommonFilter):
self.current_patchset = not reject_current_patchset
else:
self.current_patchset = current_patchset
+ if reject_draft is not None:
+ self.draft = not reject_draft
+ else:
+ self.draft = draft
self.labels = labels
self.reject_labels = reject_labels
@@ -496,12 +501,14 @@ class GithubRefFilter(RefFilter, GithubCommonFilter):
if self.reject_reviews:
ret += (' reject-reviews: %s' %
str(self.reject_reviews))
- if self.open:
+ if self.open is not None:
ret += ' open: %s' % self.open
- if self.merged:
+ if self.merged is not None:
ret += ' merged: %s' % self.merged
- if self.current_patchset:
+ if self.current_patchset is not None:
ret += ' current-patchset: %s' % self.current_patchset
+ if self.draft is not None:
+ ret += ' draft: %s' % self.draft
if self.labels:
ret += ' labels: %s' % self.labels
if self.reject_labels:
@@ -521,7 +528,8 @@ class GithubRefFilter(RefFilter, GithubCommonFilter):
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if self.open != change.open:
- return FalseWithReason("Change is not a PR")
+ return FalseWithReason(
+ "Change does not match open requirement")
else:
return FalseWithReason("Change is not a PR")
@@ -530,7 +538,8 @@ class GithubRefFilter(RefFilter, GithubCommonFilter):
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if self.merged != change.is_merged:
- return FalseWithReason("Change is not a PR")
+ return FalseWithReason(
+ "Change does not match merged requirement")
else:
return FalseWithReason("Change is not a PR")
@@ -539,7 +548,18 @@ class GithubRefFilter(RefFilter, GithubCommonFilter):
# and cannot possibly pass this test.
if hasattr(change, 'number'):
if self.current_patchset != change.is_current_patchset:
- return FalseWithReason("Change is not current")
+ return FalseWithReason(
+ "Change does not match current-patchset requirement")
+ else:
+ return FalseWithReason("Change is not a PR")
+
+ if self.draft 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.draft != change.draft:
+ return FalseWithReason(
+ "Change does not match draft requirement")
else:
return FalseWithReason("Change is not a PR")
diff --git a/zuul/driver/github/githubsource.py b/zuul/driver/github/githubsource.py
index 7d4815237..bdc373f79 100644
--- a/zuul/driver/github/githubsource.py
+++ b/zuul/driver/github/githubsource.py
@@ -169,6 +169,7 @@ class GithubSource(BaseSource):
open=config.get('open'),
merged=config.get('merged'),
current_patchset=config.get('current-patchset'),
+ draft=config.get('draft'),
labels=to_list(config.get('label')),
)
return [f]
@@ -182,6 +183,7 @@ class GithubSource(BaseSource):
reject_open=config.get('open'),
reject_merged=config.get('merged'),
reject_current_patchset=config.get('current-patchset'),
+ reject_draft=config.get('draft'),
)
return [f]
@@ -207,6 +209,7 @@ def getRequireSchema():
'open': bool,
'merged': bool,
'current-patchset': bool,
+ 'draft': bool,
'label': scalar_or_list(str)}
return require
@@ -217,5 +220,6 @@ def getRejectSchema():
'open': bool,
'merged': bool,
'current-patchset': bool,
+ 'draft': bool,
'label': scalar_or_list(str)}
return reject