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/+/2333426
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
changes/26/2333426/4
Lei Zhang 5 years ago committed by LUCI CQ
parent fb9c1110ef
commit 8a0efc1862

@ -2427,18 +2427,18 @@ class Changelist(object):
return [r['email'] for r in details['reviewers'].get('REVIEWER', [])]
def _get_bug_line_values(default_project, bugs):
"""Given default_project and comma separated list of bugs, yields bug line
values.
def _get_bug_line_values(default_project_prefix, bugs):
"""Given default_project_prefix and comma separated list of bugs, yields bug
line values.
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.
This function may produce more than one line, because bugdroid expects one
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']
"""
default_bugs = []
@ -2453,8 +2453,10 @@ def _get_bug_line_values(default_project, bugs):
if default_bugs:
default_bugs = ','.join(map(str, default_bugs))
if default_project:
yield '%s:%s' % (default_project, default_bugs)
if default_project_prefix:
if not default_project_prefix.endswith(':'):
default_project_prefix += ':'
yield '%s%s' % (default_project_prefix, default_bugs)
else:
yield default_bugs
for other in sorted(others):

@ -296,9 +296,15 @@ class TestGitClBasic(unittest.TestCase):
f = lambda p, bugs: list(git_cl._get_bug_line_values(p, bugs))
self.assertEqual(f('', ''), [])
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', 'chromium:123,456'), ['v8:456', 'chromium:123'])
# 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'),
['v8:456', 'chromium:123', 'v8:123'])

Loading…
Cancel
Save