Commit 12ef501b authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

Parse Bug, R, and Tbr git-footers in PRESUBMIT

This gives PRESUBMIT equal support for all the
gerrit-style footers that we're migrating to.

R=iannucci@chromium.org, tandrii@chromium.org

Bug: 710327,710803
Change-Id: I64b8f39ef923d90ebda7dd191b83d1a7cc87c776
Reviewed-on: https://chromium-review.googlesource.com/506551Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent 063814f8
......@@ -873,18 +873,25 @@ class Change(object):
raise AttributeError(self, attr)
return self.tags.get(attr)
# TODO(agable): Update these to also get "Git-Footer: Foo"-style footers.
def BugsFromDescription(self):
"""Returns all bugs referenced in the commit description."""
return [b.strip() for b in self.tags.get('BUG', '').split(',') if b.strip()]
tags = [b.strip() for b in self.tags.get('BUG', '').split(',') if b.strip()]
footers = git_footers.parse_footers(self._full_description).get('Bug', [])
return sorted(set(tags + footers))
def ReviewersFromDescription(self):
"""Returns all reviewers listed in the commit description."""
return [r.strip() for r in self.tags.get('R', '').split(',') if r.strip()]
# We don't support a "R:" git-footer for reviewers; that is in metadata.
tags = [r.strip() for r in self.tags.get('R', '').split(',') if r.strip()]
return sorted(set(tags))
def TBRsFromDescription(self):
"""Returns all TBR reviewers listed in the commit description."""
return [r.strip() for r in self.tags.get('TBR', '').split(',') if r.strip()]
tags = [r.strip() for r in self.tags.get('TBR', '').split(',') if r.strip()]
# TODO(agable): Remove support for 'Tbr:' when TBRs are programmatically
# determined by self-CR+1s.
footers = git_footers.parse_footers(self._full_description).get('Tbr', [])
return sorted(set(tags + footers))
# TODO(agable): Delete these once we're sure they're unused.
@property
......
......@@ -1605,6 +1605,27 @@ class ChangeUnittest(PresubmitTestsBase):
self.assertEquals('bar', change.DescriptionText())
self.assertEquals('bar\nWHIZ=bang', change.FullDescriptionText())
def testBugsFromDescription(self):
change = presubmit.Change(
'', 'foo\nBUG=2,1\n\nChange-Id: asdf\nBug: 3',
self.fake_root_dir, [], 0, 0, '')
self.assertEquals(['1', '2', '3'], change.BugsFromDescription())
self.assertEquals('1,2,3', change.BUG)
def testReviewersFromDescription(self):
change = presubmit.Change(
'', 'foo\nR=foo,bar\n\nChange-Id: asdf\nR: baz',
self.fake_root_dir, [], 0, 0, '')
self.assertEquals(['bar', 'foo'], change.ReviewersFromDescription())
self.assertEquals('bar,foo', change.R)
def testTBRsFromDescription(self):
change = presubmit.Change(
'', 'foo\nTBR=foo,bar\n\nChange-Id: asdf\nTBR: baz',
self.fake_root_dir, [], 0, 0, '')
self.assertEquals(['bar', 'baz', 'foo'], change.TBRsFromDescription())
self.assertEquals('bar,baz,foo', change.TBR)
def CommHelper(input_api, cmd, ret=None, **kwargs):
ret = ret or (('', None), 0)
......
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