Browse Source

Merge "Allow pipelines triggers to filter by username"

changes/73/66173/2
Jenkins 8 years ago committed by Gerrit Code Review
parent
commit
aae1d3d8c2
  1. 7
      doc/source/zuul.rst
  2. 1
      zuul/layoutvalidator.py
  3. 17
      zuul/model.py
  4. 4
      zuul/scheduler.py

7
doc/source/zuul.rst

@ -333,6 +333,13 @@ explanation of each of the parameters::
greedy matchers and to escapes dots!
Example: ``email_filter: ^.*?@example\.org$``.
*username_filter*
This is used for any event. It takes a regex applied on the performer
username, i.e. Gerrit account name. If you want to specify several
username filters, you must use a YAML list. Make sure to use non greedy
matchers and to escapes dots!
Example: ``username_filter: ^jenkins$``.
*comment_filter*
This is only used for ``comment-added`` events. It accepts a list of
regexes that are searched for in the comment string. If any of these

1
zuul/layoutvalidator.py

@ -44,6 +44,7 @@ class LayoutSchema(object):
'ref-updated')),
'comment_filter': toList(str),
'email_filter': toList(str),
'username_filter': toList(str),
'branch': toList(str),
'ref': toList(str),
'approval': toList(variable_dict),

17
zuul/model.py

@ -874,17 +874,20 @@ class TriggerEvent(object):
class EventFilter(object):
def __init__(self, types=[], branches=[], refs=[], approvals={},
comment_filters=[], email_filters=[], timespecs=[]):
comment_filters=[], email_filters=[], username_filters=[],
timespecs=[]):
self._types = types
self._branches = branches
self._refs = refs
self._comment_filters = comment_filters
self._email_filters = email_filters
self._username_filters = username_filters
self.types = [re.compile(x) for x in types]
self.branches = [re.compile(x) for x in branches]
self.refs = [re.compile(x) for x in refs]
self.comment_filters = [re.compile(x) for x in comment_filters]
self.email_filters = [re.compile(x) for x in email_filters]
self.username_filters = [re.compile(x) for x in username_filters]
self.approvals = approvals
self.timespecs = timespecs
@ -904,6 +907,8 @@ class EventFilter(object):
ret += ' comment_filters: %s' % ', '.join(self._comment_filters)
if self._email_filters:
ret += ' email_filters: %s' % ', '.join(self._email_filters)
if self._username_filters:
ret += ' username_filters: %s' % ', '.join(self._username_filters)
if self.timespecs:
ret += ' timespecs: %s' % ', '.join(self.timespecs)
ret += '>'
@ -961,6 +966,16 @@ class EventFilter(object):
if self.email_filters and not matches_email_filter:
return False
# username_filters are ORed
account_username = event.account.get('username')
matches_username_filter = False
for username_filter in self.username_filters:
if (account_username is not None and
username_filter.search(account_username)):
matches_username_filter = True
if self.username_filters and not matches_username_filter:
return False
# approvals are ANDed
for category, value in self.approvals.items():
matches_approval = False

4
zuul/scheduler.py

@ -231,7 +231,9 @@ class Scheduler(threading.Thread):
comment_filters=
toList(trigger.get('comment_filter')),
email_filters=
toList(trigger.get('email_filter')))
toList(trigger.get('email_filter')),
username_filters=
toList(trigger.get('username_filter')))
manager.event_filters.append(f)
elif 'timer' in conf_pipeline['trigger']:
pipeline.trigger = self.triggers['timer']

Loading…
Cancel
Save