Commit cf49cb82 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

[presubmit][owners] Skip owners check when Owners-Override is +1

Add support for Owners-Override label to allow trusted bots, sheriffs,
and global owners to bypass owners checks.

Bug: 1093627
Change-Id: Ie217369a67e4060807c0a12f84430e30a7c57daa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2530488Reviewed-by: 's avatarYulan Lin <yulanlin@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 02d4b825
......@@ -1122,10 +1122,17 @@ def CheckOwnersFormat(input_api, output_api):
def CheckOwners(input_api, output_api, source_file_filter=None):
# Skip OWNERS check when Bot-Commit label is approved.
if (input_api.change.issue
and input_api.gerrit.IsBotCommitApproved(input_api.change.issue)):
return []
if input_api.change.issue:
# Skip OWNERS check when Bot-Commit label is approved. This label is
# intended for commits made by trusted bots that don't require review nor
# owners approval.
if input_api.gerrit.IsBotCommitApproved(input_api.change.issue):
return []
# Skip OWNERS check when Owners-Override label is approved. This is intended
# for global owners, trusted bots, and on-call sheriffs. Review is still
# required for these changes.
if input_api.gerrit.IsOwnersOverrideApproved(input_api.change.issue):
return []
affected_files = set([f.LocalPath() for f in
input_api.change.AffectedFiles(file_filter=source_file_filter)])
......
......@@ -446,6 +446,9 @@ class GerritAccessor(object):
def IsBotCommitApproved(self, issue):
return bool(self._GetApproversForLabel(issue, 'Bot-Commit'))
def IsOwnersOverrideApproved(self, issue):
return bool(self._GetApproversForLabel(issue, 'Owners-Override'))
def GetChangeOwner(self, issue):
return self.GetChangeInfo(issue)['owner']['email']
......
......@@ -2778,6 +2778,33 @@ the current line as well!
response=response,
expected_output='')
def testCannedCheckOwners_OwnersOverride(self):
response = {
"owner": {"email": "john@example.com"},
"labels": {"Owners-Override": {
u'all': [
{
u'email': u'sheriff@example.com',
u'value': 1
},
],
u'approved': {u'email': u'sheriff@example.org'},
u'default_value': 0,
u'values': {u' 0': u'No score',
u'+1': u'Looks good to me'},
}},
"reviewers": {"REVIEWER": [{u'email': u'sheriff@example.com'}]},
}
self.AssertOwnersWorks(approvers=set(),
response=response,
is_committing=True,
expected_output='')
self.AssertOwnersWorks(approvers=set(),
is_committing=False,
response=response,
expected_output='')
def testCannedCheckOwners_Approved(self):
response = {
"owner": {"email": "john@example.com"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment