Commit 067ef5d8 authored by Edward Lesmes's avatar Edward Lesmes Committed by Commit Bot

Add support for checking that OWNERS files are correctly formatted.

Bug: 789773
Change-Id: I4c6c676a821fad33a34ef6c46468af95cdf6c0ec
Reviewed-on: https://chromium-review.googlesource.com/1020073
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
parent 741afe8c
...@@ -826,6 +826,22 @@ def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings, ...@@ -826,6 +826,22 @@ def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings,
return [] return []
def CheckOwnersFormat(input_api, output_api):
affected_files = set([
f.LocalPath()
for f in input_api.change.AffectedFiles()
if 'OWNERS' in f.LocalPath() and f.Action() != 'D'
])
if not affected_files:
return []
try:
input_api.owners_db.load_data_needed_for(affected_files)
return []
except Exception as e:
return [output_api.PresubmitError(
'Error parsing OWNERS files:\n%s' % e)]
def CheckOwners(input_api, output_api, source_file_filter=None): def CheckOwners(input_api, output_api, source_file_filter=None):
affected_files = set([f.LocalPath() for f in affected_files = set([f.LocalPath() for f in
input_api.change.AffectedFiles(file_filter=source_file_filter)]) input_api.change.AffectedFiles(file_filter=source_file_filter)])
......
...@@ -1726,6 +1726,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1726,6 +1726,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks',
'CheckLicense', 'CheckLicense',
'CheckOwners', 'CheckOwners',
'CheckOwnersFormat',
'CheckPatchFormatted', 'CheckPatchFormatted',
'CheckGNFormatted', 'CheckGNFormatted',
'CheckSingletonInHeaders', 'CheckSingletonInHeaders',
...@@ -2342,6 +2343,48 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -2342,6 +2343,48 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results[0].__class__, self.assertEquals(results[0].__class__,
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult)
def GetInputApiWithOWNERS(self, owners_content):
affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file.LocalPath = lambda: 'OWNERS'
affected_file.Action = lambda: 'M'
change = self.mox.CreateMock(presubmit.Change)
change.AffectedFiles = lambda: [affected_file]
input_api = self.MockInputApi(None, False)
input_api.change = change
os.path.exists = lambda _: True
owners_file = presubmit.cStringIO.StringIO(owners_content)
fopen = lambda *args: owners_file
input_api.owners_db = owners.Database('', fopen, os.path)
return input_api
def testCheckOwnersFormatWorks(self):
input_api = self.GetInputApiWithOWNERS('\n'.join([
'set noparent',
'per-file lalala = lemur@chromium.org',
]))
self.assertEqual(
[],
presubmit_canned_checks.CheckOwnersFormat(
input_api, presubmit.OutputApi)
)
def testCheckOwnersFormatFails(self):
input_api = self.GetInputApiWithOWNERS('\n'.join([
'set noparent',
'invalid format',
]))
results = presubmit_canned_checks.CheckOwnersFormat(
input_api, presubmit.OutputApi)
self.assertEqual(1, len(results))
self.assertIsInstance(results[0], presubmit.OutputApi.PresubmitError)
def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None,
reviewers=None, is_committing=True, reviewers=None, is_committing=True,
response=None, uncovered_files=None, expected_output='', response=None, uncovered_files=None, expected_output='',
......
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