diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index f5d724e98d..e4d5e63cbc 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -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)]) diff --git a/presubmit_support.py b/presubmit_support.py index c84933151a..43c2c1d3d2 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -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'] diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index f5213c6ff2..c861296ae3 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -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"},