Commit bc50eb4a authored by maruel@chromium.org's avatar maruel@chromium.org

Add CheckChangeHasDescription.

TEST=unit test
BUG=none

Review URL: http://codereview.chromium.org/119427

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18077 0039d316-1c4b-4281-b951-d872f2087c98
parent 5de1397a
...@@ -53,6 +53,16 @@ def CheckDoNotSubmitInDescription(input_api, output_api): ...@@ -53,6 +53,16 @@ def CheckDoNotSubmitInDescription(input_api, output_api):
return [] return []
def CheckChangeHasDescription(input_api, output_api):
"""Checks the CL description is not empty."""
text = input_api.change.DescriptionText()
if text.strip() == '':
if input_api.is_committing:
return [output_api.PresubmitError("Add a description.")]
else:
return [output_api.PresubmitNotifyResult("Add a description.")]
return []
### Content checks ### Content checks
def CheckDoNotSubmitInFiles(input_api, output_api): def CheckDoNotSubmitInFiles(input_api, output_api):
......
...@@ -937,9 +937,9 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -937,9 +937,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
def testMembersChanged(self): def testMembersChanged(self):
self.mox.ReplayAll() self.mox.ReplayAll()
members = [ members = [
'CheckChangeHasBugField', 'CheckChangeHasOnlyOneEol', 'CheckChangeHasBugField', 'CheckChangeHasDescription',
'CheckChangeHasNoCR', 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
'CheckChangeHasNoTabs', 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
'CheckChangeHasQaField', 'CheckChangeHasTestedField', 'CheckChangeHasQaField', 'CheckChangeHasTestedField',
'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle',
'CheckDoNotSubmit', 'CheckDoNotSubmit',
...@@ -949,11 +949,14 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -949,11 +949,14 @@ class CannedChecksUnittest(PresubmitTestsBase):
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(presubmit_canned_checks, members) self.compareMembers(presubmit_canned_checks, members)
def DescriptionTest(self, check, description1, description2, error_type): def DescriptionTest(self, check, description1, description2, error_type,
committing):
input_api1 = self.MockInputApi() input_api1 = self.MockInputApi()
input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) input_api1.is_committing = committing
input_api1.change = self.MakeBasicChange('foo', description1)
input_api2 = self.MockInputApi() input_api2 = self.MockInputApi()
input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2) input_api2.is_committing = committing
input_api2.change = self.MakeBasicChange('foo', description2)
self.mox.ReplayAll() self.mox.ReplayAll()
results1 = check(input_api1, presubmit.OutputApi) results1 = check(input_api1, presubmit.OutputApi)
...@@ -1013,28 +1016,44 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1013,28 +1016,44 @@ class CannedChecksUnittest(PresubmitTestsBase):
def testCannedCheckChangeHasBugField(self): def testCannedCheckChangeHasBugField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField,
'BUG=1234', '', 'Foo\nBUG=1234', 'Foo\n',
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult,
False)
def testCheckChangeHasDescription(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription,
'Bleh', '',
presubmit.OutputApi.PresubmitNotifyResult,
False)
self.mox.VerifyAll()
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription,
'Bleh', '',
presubmit.OutputApi.PresubmitError,
True)
def testCannedCheckChangeHasTestField(self): def testCannedCheckChangeHasTestField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField, self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField,
'TEST=did some stuff', '', 'Foo\nTEST=did some stuff', 'Foo\n',
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult,
False)
def testCannedCheckChangeHasTestedField(self): def testCannedCheckChangeHasTestedField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField, self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField,
'TESTED=did some stuff', '', 'Foo\nTESTED=did some stuff', 'Foo\n',
presubmit.OutputApi.PresubmitError) presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckChangeHasQAField(self): def testCannedCheckChangeHasQAField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField, self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField,
'QA=BSOD your machine', '', 'Foo\nQA=BSOD your machine', 'Foo\n',
presubmit.OutputApi.PresubmitError) presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckDoNotSubmitInDescription(self): def testCannedCheckDoNotSubmitInDescription(self):
self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription, self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription,
'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', 'Foo\nDO NOTSUBMIT', 'Foo\nDO NOT ' + 'SUBMIT',
presubmit.OutputApi.PresubmitError) presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckDoNotSubmitInFiles(self): def testCannedCheckDoNotSubmitInFiles(self):
self.ContentTest( self.ContentTest(
......
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