diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index d4714e5d4..16c149765 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1127,12 +1127,17 @@ def CheckOwnersFormat(input_api, output_api): def CheckOwners( input_api, output_api, source_file_filter=None, allow_tbr=True): - # 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.change.issue - and input_api.gerrit.IsOwnersOverrideApproved(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 [] # Ignore tbr if not allowed for this repo. tbr = input_api.tbr and allow_tbr diff --git a/presubmit_support.py b/presubmit_support.py index c53ed8fa1..3a05c4b8e 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -446,6 +446,9 @@ class GerritAccessor(object): return [v for v in label_info.get('all', []) if v.get('value', 0) == max_value] + def IsBotCommitApproved(self, issue): + return bool(self._GetApproversForLabel(issue, 'Bot-Commit')) + def IsOwnersOverrideApproved(self, issue): return bool(self._GetApproversForLabel(issue, 'Owners-Override')) diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 739a2e339..fc4e1df40 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2795,6 +2795,37 @@ the current line as well! response=response, expected_output='') + def testCannedCheckOwners_BotCommit(self): + response = { + "owner": {"email": "john@example.com"}, + "labels": {"Bot-Commit": { + u'all': [ + { + u'email': u'bot@example.com', + u'value': 1 + }, + ], + u'approved': {u'email': u'bot@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'bot@example.com'}]}, + } + self.AssertOwnersWorks( + approvers=set(), + modified_files={'foo/xyz.cc': ['john@example.com']}, + response=response, + is_committing=True, + expected_output='') + + self.AssertOwnersWorks( + approvers=set(), + modified_files={'foo/xyz.cc': ['john@example.com']}, + is_committing=False, + response=response, + expected_output='') + def testCannedCheckOwners_OwnersOverride(self): response = { "owner": {"email": "john@example.com"},