Commit 8a0efc18 authored by Lei Zhang's avatar Lei Zhang Committed by LUCI CQ

Handle BUG_PREFIX correctly when populating Bug: lines.

Right now git_cl.py inserts an extra colon if the bug prefix ends with
a colon. Fix this by detecting whether the bug prefix ends with a colon
or not, and only inserting the colon when necessary.

Bug: 1111955
Change-Id: I3db199435087abb17b9600fc208b11d2d8e6a615
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2333426Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
parent fb9c1110
...@@ -2427,18 +2427,18 @@ class Changelist(object): ...@@ -2427,18 +2427,18 @@ class Changelist(object):
return [r['email'] for r in details['reviewers'].get('REVIEWER', [])] return [r['email'] for r in details['reviewers'].get('REVIEWER', [])]
def _get_bug_line_values(default_project, bugs): def _get_bug_line_values(default_project_prefix, bugs):
"""Given default_project and comma separated list of bugs, yields bug line """Given default_project_prefix and comma separated list of bugs, yields bug
values. line values.
Each bug can be either: Each bug can be either:
* a number, which is combined with default_project * a number, which is combined with default_project_prefix
* string, which is left as is. * string, which is left as is.
This function may produce more than one line, because bugdroid expects one This function may produce more than one line, because bugdroid expects one
project per line. project per line.
>>> list(_get_bug_line_values('v8', '123,chromium:789')) >>> list(_get_bug_line_values('v8:', '123,chromium:789'))
['v8:123', 'chromium:789'] ['v8:123', 'chromium:789']
""" """
default_bugs = [] default_bugs = []
...@@ -2453,8 +2453,10 @@ def _get_bug_line_values(default_project, bugs): ...@@ -2453,8 +2453,10 @@ def _get_bug_line_values(default_project, bugs):
if default_bugs: if default_bugs:
default_bugs = ','.join(map(str, default_bugs)) default_bugs = ','.join(map(str, default_bugs))
if default_project: if default_project_prefix:
yield '%s:%s' % (default_project, default_bugs) if not default_project_prefix.endswith(':'):
default_project_prefix += ':'
yield '%s%s' % (default_project_prefix, default_bugs)
else: else:
yield default_bugs yield default_bugs
for other in sorted(others): for other in sorted(others):
......
...@@ -296,9 +296,15 @@ class TestGitClBasic(unittest.TestCase): ...@@ -296,9 +296,15 @@ class TestGitClBasic(unittest.TestCase):
f = lambda p, bugs: list(git_cl._get_bug_line_values(p, bugs)) f = lambda p, bugs: list(git_cl._get_bug_line_values(p, bugs))
self.assertEqual(f('', ''), []) self.assertEqual(f('', ''), [])
self.assertEqual(f('', '123,v8:456'), ['123', 'v8:456']) self.assertEqual(f('', '123,v8:456'), ['123', 'v8:456'])
# Prefix that ends with colon.
self.assertEqual(f('v8:', '456'), ['v8:456'])
self.assertEqual(f('v8:', 'chromium:123,456'), ['v8:456', 'chromium:123'])
# Prefix that ends without colon.
self.assertEqual(f('v8', '456'), ['v8:456']) self.assertEqual(f('v8', '456'), ['v8:456'])
self.assertEqual(f('v8', 'chromium:123,456'), ['v8:456', 'chromium:123']) self.assertEqual(f('v8', 'chromium:123,456'), ['v8:456', 'chromium:123'])
# Not nice, but not worth carying. # Not nice, but not worth carying.
self.assertEqual(f('v8:', 'chromium:123,456,v8:123'),
['v8:456', 'chromium:123', 'v8:123'])
self.assertEqual(f('v8', 'chromium:123,456,v8:123'), self.assertEqual(f('v8', 'chromium:123,456,v8:123'),
['v8:456', 'chromium:123', 'v8:123']) ['v8:456', 'chromium:123', 'v8:123'])
......
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