Rename "filter" parameters
The word "filter" doesn't help very much with clarity and it's sometimes confusing whether you need to use "username" or "username_filter". Just drop the filter suffix where it's used. Tests are intentionally not altered in this change to verify backwords compatibility. Change-Id: I2edddad2e1f6ce4c86265de5f7a8cda1ebf436df
This commit is contained in:
parent
9c17dbf763
commit
1fbfceb04b
|
@ -401,28 +401,40 @@ explanation of each of the parameters::
|
||||||
``code-review: 2`` matches a ``+2`` vote on the code review category.
|
``code-review: 2`` matches a ``+2`` vote on the code review category.
|
||||||
Multiple approvals may be listed.
|
Multiple approvals may be listed.
|
||||||
|
|
||||||
*email_filter*
|
*email*
|
||||||
This is used for any event. It takes a regex applied on the performer
|
This is used for any event. It takes a regex applied on the performer
|
||||||
email, i.e. Gerrit account email address. If you want to specify
|
email, i.e. Gerrit account email address. If you want to specify
|
||||||
several email filters, you must use a YAML list. Make sure to use non
|
several email filters, you must use a YAML list. Make sure to use non
|
||||||
greedy matchers and to escapes dots!
|
greedy matchers and to escapes dots!
|
||||||
Example: ``email_filter: ^.*?@example\.org$``.
|
Example: ``email: ^.*?@example\.org$``.
|
||||||
|
|
||||||
*username_filter*
|
*email_filter* (deprecated)
|
||||||
|
A deprecated alternate spelling of *email*. Only one of *email* or
|
||||||
|
*email_filter* should be used.
|
||||||
|
|
||||||
|
*username*
|
||||||
This is used for any event. It takes a regex applied on the performer
|
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, 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
|
username filters, you must use a YAML list. Make sure to use non greedy
|
||||||
matchers and to escapes dots!
|
matchers and to escapes dots!
|
||||||
Example: ``username_filter: ^jenkins$``.
|
Example: ``username: ^jenkins$``.
|
||||||
|
|
||||||
*comment_filter*
|
*username_filter* (deprecated)
|
||||||
|
A deprecated alternate spelling of *username*. Only one of *username* or
|
||||||
|
*username_filter* should be used.
|
||||||
|
|
||||||
|
*comment*
|
||||||
This is only used for ``comment-added`` events. It accepts a list of
|
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
|
regexes that are searched for in the comment string. If any of these
|
||||||
regexes matches a portion of the comment string the trigger is
|
regexes matches a portion of the comment string the trigger is
|
||||||
matched. ``comment_filter: retrigger`` will match when comments
|
matched. ``comment: retrigger`` will match when comments
|
||||||
containing 'retrigger' somewhere in the comment text are added to a
|
containing 'retrigger' somewhere in the comment text are added to a
|
||||||
change.
|
change.
|
||||||
|
|
||||||
|
*comment_filter* (deprecated)
|
||||||
|
A deprecated alternate spelling of *comment*. Only one of *comment* or
|
||||||
|
*comment_filter* should be used.
|
||||||
|
|
||||||
*require-approval*
|
*require-approval*
|
||||||
This may be used for any event. It requires that a certain kind
|
This may be used for any event. It requires that a certain kind
|
||||||
of approval be present for the current patchset of the change (the
|
of approval be present for the current patchset of the change (the
|
||||||
|
@ -457,10 +469,14 @@ explanation of each of the parameters::
|
||||||
*username*
|
*username*
|
||||||
If present, an approval from this username is required.
|
If present, an approval from this username is required.
|
||||||
|
|
||||||
*email-filter*
|
*email*
|
||||||
If present, an approval with this email address is required. It
|
If present, an approval with this email address is required. It
|
||||||
is treated as a regular expression as above.
|
is treated as a regular expression as above.
|
||||||
|
|
||||||
|
*email-filter* (deprecated)
|
||||||
|
A deprecated alternate spelling of *email*. Only one of *email* or
|
||||||
|
*email_filter* should be used.
|
||||||
|
|
||||||
*older-than*
|
*older-than*
|
||||||
If present, the approval must be older than this amount of time
|
If present, the approval must be older than this amount of time
|
||||||
to match. Provide a time interval as a number with a suffix of
|
to match. Provide a time interval as a number with a suffix of
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright 2013 OpenStack Foundation
|
# Copyright 2013 OpenStack Foundation
|
||||||
# Copyright 2013 Antoine "hashar" Musso
|
# Copyright 2013 Antoine "hashar" Musso
|
||||||
# Copyright 2013 Wikimedia Foundation Inc.
|
# Copyright 2013 Wikimedia Foundation Inc.
|
||||||
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -37,6 +38,7 @@ class LayoutSchema(object):
|
||||||
|
|
||||||
require_approval = v.Schema({'username': str,
|
require_approval = v.Schema({'username': str,
|
||||||
'email-filter': str,
|
'email-filter': str,
|
||||||
|
'email': str,
|
||||||
'older-than': str,
|
'older-than': str,
|
||||||
'newer-than': str,
|
'newer-than': str,
|
||||||
}, extra=True)
|
}, extra=True)
|
||||||
|
@ -49,8 +51,11 @@ class LayoutSchema(object):
|
||||||
'comment-added',
|
'comment-added',
|
||||||
'ref-updated')),
|
'ref-updated')),
|
||||||
'comment_filter': toList(str),
|
'comment_filter': toList(str),
|
||||||
|
'comment': toList(str),
|
||||||
'email_filter': toList(str),
|
'email_filter': toList(str),
|
||||||
|
'email': toList(str),
|
||||||
'username_filter': toList(str),
|
'username_filter': toList(str),
|
||||||
|
'username': toList(str),
|
||||||
'branch': toList(str),
|
'branch': toList(str),
|
||||||
'ref': toList(str),
|
'ref': toList(str),
|
||||||
'approval': toList(variable_dict),
|
'approval': toList(variable_dict),
|
||||||
|
|
|
@ -987,8 +987,8 @@ class BaseFilter(object):
|
||||||
for k, v in a.items():
|
for k, v in a.items():
|
||||||
if k == 'username':
|
if k == 'username':
|
||||||
pass
|
pass
|
||||||
elif k == 'email-filter':
|
elif k in ['email', 'email-filter']:
|
||||||
a[k] = re.compile(v)
|
a['email'] = re.compile(v)
|
||||||
elif k == 'newer-than':
|
elif k == 'newer-than':
|
||||||
a[k] = time_to_seconds(v)
|
a[k] = time_to_seconds(v)
|
||||||
elif k == 'older-than':
|
elif k == 'older-than':
|
||||||
|
@ -996,6 +996,8 @@ class BaseFilter(object):
|
||||||
else:
|
else:
|
||||||
if not isinstance(v, list):
|
if not isinstance(v, list):
|
||||||
a[k] = [v]
|
a[k] = [v]
|
||||||
|
if 'email-filter' in a:
|
||||||
|
del a['email-filter']
|
||||||
|
|
||||||
def matchesRequiredApprovals(self, change):
|
def matchesRequiredApprovals(self, change):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
@ -1010,7 +1012,7 @@ class BaseFilter(object):
|
||||||
if k == 'username':
|
if k == 'username':
|
||||||
if (by.get('username', '') != v):
|
if (by.get('username', '') != v):
|
||||||
found_approval = False
|
found_approval = False
|
||||||
elif k == 'email-filter':
|
elif k == 'email':
|
||||||
if (not v.search(by.get('email', ''))):
|
if (not v.search(by.get('email', ''))):
|
||||||
found_approval = False
|
found_approval = False
|
||||||
elif k == 'newer-than':
|
elif k == 'newer-than':
|
||||||
|
@ -1035,22 +1037,22 @@ class BaseFilter(object):
|
||||||
|
|
||||||
class EventFilter(BaseFilter):
|
class EventFilter(BaseFilter):
|
||||||
def __init__(self, types=[], branches=[], refs=[], event_approvals={},
|
def __init__(self, types=[], branches=[], refs=[], event_approvals={},
|
||||||
comment_filters=[], email_filters=[], username_filters=[],
|
comments=[], emails=[], usernames=[], timespecs=[],
|
||||||
timespecs=[], required_approvals=[]):
|
required_approvals=[]):
|
||||||
super(EventFilter, self).__init__(
|
super(EventFilter, self).__init__(
|
||||||
required_approvals=required_approvals)
|
required_approvals=required_approvals)
|
||||||
self._types = types
|
self._types = types
|
||||||
self._branches = branches
|
self._branches = branches
|
||||||
self._refs = refs
|
self._refs = refs
|
||||||
self._comment_filters = comment_filters
|
self._comments = comments
|
||||||
self._email_filters = email_filters
|
self._emails = emails
|
||||||
self._username_filters = username_filters
|
self._usernames = usernames
|
||||||
self.types = [re.compile(x) for x in types]
|
self.types = [re.compile(x) for x in types]
|
||||||
self.branches = [re.compile(x) for x in branches]
|
self.branches = [re.compile(x) for x in branches]
|
||||||
self.refs = [re.compile(x) for x in refs]
|
self.refs = [re.compile(x) for x in refs]
|
||||||
self.comment_filters = [re.compile(x) for x in comment_filters]
|
self.comments = [re.compile(x) for x in comments]
|
||||||
self.email_filters = [re.compile(x) for x in email_filters]
|
self.emails = [re.compile(x) for x in emails]
|
||||||
self.username_filters = [re.compile(x) for x in username_filters]
|
self.usernames = [re.compile(x) for x in usernames]
|
||||||
self.event_approvals = event_approvals
|
self.event_approvals = event_approvals
|
||||||
self.timespecs = timespecs
|
self.timespecs = timespecs
|
||||||
|
|
||||||
|
@ -1069,12 +1071,12 @@ class EventFilter(BaseFilter):
|
||||||
if self.required_approvals:
|
if self.required_approvals:
|
||||||
ret += ' required_approvals: %s' % ', '.join(
|
ret += ' required_approvals: %s' % ', '.join(
|
||||||
['%s' % a for a in self.required_approvals])
|
['%s' % a for a in self.required_approvals])
|
||||||
if self._comment_filters:
|
if self._comments:
|
||||||
ret += ' comment_filters: %s' % ', '.join(self._comment_filters)
|
ret += ' comments: %s' % ', '.join(self._comments)
|
||||||
if self._email_filters:
|
if self._emails:
|
||||||
ret += ' email_filters: %s' % ', '.join(self._email_filters)
|
ret += ' emails: %s' % ', '.join(self._emails)
|
||||||
if self._username_filters:
|
if self._usernames:
|
||||||
ret += ' username_filters: %s' % ', '.join(self._username_filters)
|
ret += ' username_filters: %s' % ', '.join(self._usernames)
|
||||||
if self.timespecs:
|
if self.timespecs:
|
||||||
ret += ' timespecs: %s' % ', '.join(self.timespecs)
|
ret += ' timespecs: %s' % ', '.join(self.timespecs)
|
||||||
ret += '>'
|
ret += '>'
|
||||||
|
@ -1106,36 +1108,36 @@ class EventFilter(BaseFilter):
|
||||||
if self.refs and not matches_ref:
|
if self.refs and not matches_ref:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# comment_filters are ORed
|
# comments are ORed
|
||||||
matches_comment_filter = False
|
matches_comment_re = False
|
||||||
for comment_filter in self.comment_filters:
|
for comment_re in self.comments:
|
||||||
if (event.comment is not None and
|
if (event.comment is not None and
|
||||||
comment_filter.search(event.comment)):
|
comment_re.search(event.comment)):
|
||||||
matches_comment_filter = True
|
matches_comment_re = True
|
||||||
if self.comment_filters and not matches_comment_filter:
|
if self.comments and not matches_comment_re:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# We better have an account provided by Gerrit to do
|
# We better have an account provided by Gerrit to do
|
||||||
# email filtering.
|
# email filtering.
|
||||||
if event.account is not None:
|
if event.account is not None:
|
||||||
account_email = event.account.get('email')
|
account_email = event.account.get('email')
|
||||||
# email_filters are ORed
|
# emails are ORed
|
||||||
matches_email_filter = False
|
matches_email_re = False
|
||||||
for email_filter in self.email_filters:
|
for email_re in self.emails:
|
||||||
if (account_email is not None and
|
if (account_email is not None and
|
||||||
email_filter.search(account_email)):
|
email_re.search(account_email)):
|
||||||
matches_email_filter = True
|
matches_email_re = True
|
||||||
if self.email_filters and not matches_email_filter:
|
if self.emails and not matches_email_re:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# username_filters are ORed
|
# usernames are ORed
|
||||||
account_username = event.account.get('username')
|
account_username = event.account.get('username')
|
||||||
matches_username_filter = False
|
matches_username_re = False
|
||||||
for username_filter in self.username_filters:
|
for username_re in self.usernames:
|
||||||
if (account_username is not None and
|
if (account_username is not None and
|
||||||
username_filter.search(account_username)):
|
username_re.search(account_username)):
|
||||||
matches_username_filter = True
|
matches_username_re = True
|
||||||
if self.username_filters and not matches_username_filter:
|
if self.usernames and not matches_username_re:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# approvals are ANDed
|
# approvals are ANDed
|
||||||
|
|
|
@ -292,16 +292,23 @@ class Scheduler(threading.Thread):
|
||||||
for approval_dict in toList(trigger.get('approval')):
|
for approval_dict in toList(trigger.get('approval')):
|
||||||
for k, v in approval_dict.items():
|
for k, v in approval_dict.items():
|
||||||
approvals[k] = v
|
approvals[k] = v
|
||||||
|
# Backwards compat for *_filter versions of these args
|
||||||
|
comments = toList(trigger.get('comment'))
|
||||||
|
if not comments:
|
||||||
|
comments = toList(trigger.get('comment_filter'))
|
||||||
|
emails = toList(trigger.get('email'))
|
||||||
|
if not emails:
|
||||||
|
emails = toList(trigger.get('email_filter'))
|
||||||
|
usernames = toList(trigger.get('username'))
|
||||||
|
if not usernames:
|
||||||
|
usernames = toList(trigger.get('username_filter'))
|
||||||
f = EventFilter(types=toList(trigger['event']),
|
f = EventFilter(types=toList(trigger['event']),
|
||||||
branches=toList(trigger.get('branch')),
|
branches=toList(trigger.get('branch')),
|
||||||
refs=toList(trigger.get('ref')),
|
refs=toList(trigger.get('ref')),
|
||||||
event_approvals=approvals,
|
event_approvals=approvals,
|
||||||
comment_filters=
|
comments=comments,
|
||||||
toList(trigger.get('comment_filter')),
|
emails=emails,
|
||||||
email_filters=
|
usernames=usernames,
|
||||||
toList(trigger.get('email_filter')),
|
|
||||||
username_filters=
|
|
||||||
toList(trigger.get('username_filter')),
|
|
||||||
required_approvals=
|
required_approvals=
|
||||||
toList(trigger.get('require-approval')))
|
toList(trigger.get('require-approval')))
|
||||||
manager.event_filters.append(f)
|
manager.event_filters.append(f)
|
||||||
|
|
Loading…
Reference in New Issue