From aad3ae2fe13cbd223c4cb51cbdde188b6308ff9d Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 18 May 2017 14:11:29 -0700 Subject: Add driver-specific pipeline requirements As we expand the Github driver, we're seeing a need to specify driver-specific pipeline requirements. To accomplish this, bump the require/reject pipeline keywords down a level underneath connection names. This lets users specify per-source pipeline requirements. This adds new API methods for sources to create the new pipeline filters (by returning instances or subclasses of RefFilter, which used to be called ChangeishFilter). This change also creates and/or moves driver-specific subclasses of EventFilter and TriggerEvent in(to) their respective drivers. Change-Id: Ia56c254e3aa591a688103db5b04b3dddae7b2da4 --- zuul/driver/gerrit/gerrittrigger.py | 76 +++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'zuul/driver/gerrit/gerrittrigger.py') diff --git a/zuul/driver/gerrit/gerrittrigger.py b/zuul/driver/gerrit/gerrittrigger.py index 70c65fd3a..706b7df51 100644 --- a/zuul/driver/gerrit/gerrittrigger.py +++ b/zuul/driver/gerrit/gerrittrigger.py @@ -14,8 +14,9 @@ import logging import voluptuous as v -from zuul.model import EventFilter from zuul.trigger import BaseTrigger +from zuul.driver.gerrit.gerritmodel import GerritEventFilter +from zuul.driver.util import scalar_or_list, to_list class GerritTrigger(BaseTrigger): @@ -23,43 +24,36 @@ class GerritTrigger(BaseTrigger): log = logging.getLogger("zuul.GerritTrigger") def getEventFilters(self, trigger_conf): - def toList(item): - if not item: - return [] - if isinstance(item, list): - return item - return [item] - efilters = [] - for trigger in toList(trigger_conf): + for trigger in to_list(trigger_conf): approvals = {} - for approval_dict in toList(trigger.get('approval')): + for approval_dict in to_list(trigger.get('approval')): for key, val in approval_dict.items(): approvals[key] = val # Backwards compat for *_filter versions of these args - comments = toList(trigger.get('comment')) + comments = to_list(trigger.get('comment')) if not comments: - comments = toList(trigger.get('comment_filter')) - emails = toList(trigger.get('email')) + comments = to_list(trigger.get('comment_filter')) + emails = to_list(trigger.get('email')) if not emails: - emails = toList(trigger.get('email_filter')) - usernames = toList(trigger.get('username')) + emails = to_list(trigger.get('email_filter')) + usernames = to_list(trigger.get('username')) if not usernames: - usernames = toList(trigger.get('username_filter')) + usernames = to_list(trigger.get('username_filter')) ignore_deletes = trigger.get('ignore-deletes', True) - f = EventFilter( + f = GerritEventFilter( trigger=self, - types=toList(trigger['event']), - branches=toList(trigger.get('branch')), - refs=toList(trigger.get('ref')), + types=to_list(trigger['event']), + branches=to_list(trigger.get('branch')), + refs=to_list(trigger.get('ref')), event_approvals=approvals, comments=comments, emails=emails, usernames=usernames, required_approvals=( - toList(trigger.get('require-approval')) + to_list(trigger.get('require-approval')) ), - reject_approvals=toList( + reject_approvals=to_list( trigger.get('reject-approval') ), ignore_deletes=ignore_deletes @@ -80,8 +74,6 @@ def validate_conf(trigger_conf): def getSchema(): - def toList(x): - return v.Any([x], x) variable_dict = v.Schema(dict) approval = v.Schema({'username': str, @@ -93,25 +85,25 @@ def getSchema(): gerrit_trigger = { v.Required('event'): - toList(v.Any('patchset-created', - 'draft-published', - 'change-abandoned', - 'change-restored', - 'change-merged', - 'comment-added', - 'ref-updated')), - 'comment_filter': toList(str), - 'comment': toList(str), - 'email_filter': toList(str), - 'email': toList(str), - 'username_filter': toList(str), - 'username': toList(str), - 'branch': toList(str), - 'ref': toList(str), + scalar_or_list(v.Any('patchset-created', + 'draft-published', + 'change-abandoned', + 'change-restored', + 'change-merged', + 'comment-added', + 'ref-updated')), + 'comment_filter': scalar_or_list(str), + 'comment': scalar_or_list(str), + 'email_filter': scalar_or_list(str), + 'email': scalar_or_list(str), + 'username_filter': scalar_or_list(str), + 'username': scalar_or_list(str), + 'branch': scalar_or_list(str), + 'ref': scalar_or_list(str), 'ignore-deletes': bool, - 'approval': toList(variable_dict), - 'require-approval': toList(approval), - 'reject-approval': toList(approval), + 'approval': scalar_or_list(variable_dict), + 'require-approval': scalar_or_list(approval), + 'reject-approval': scalar_or_list(approval), } return gerrit_trigger -- cgit v1.2.1