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>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index fd7cd68..7bcd640 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -296,9 +296,15 @@
     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'])