Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: git_cl.py

Issue 2117483002: Implement git cl upload -b BUG --bug=BUG. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index 7913e989d0345483b70b65e303a711adcf5365fd..831e3d5e1f4b064817f21d81db92bd054fc9f0f1 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1916,7 +1916,7 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
options.tbr_owners,
change)
if not options.force:
- change_desc.prompt()
+ change_desc.prompt(bug=options.bug)
if not change_desc.description:
print('Description is empty; aborting.')
@@ -2465,7 +2465,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
ask_for_data('Press enter to edit now, Ctrl+C to abort')
if not options.force:
change_desc = ChangeDescription(message)
- change_desc.prompt()
+ change_desc.prompt(bug=options.bug)
message = change_desc.description
if not message:
DieWithError("Description is empty. Aborting...")
@@ -2478,7 +2478,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
change_desc = ChangeDescription(
options.message or CreateDescriptionFromLog(args))
if not options.force:
- change_desc.prompt()
+ change_desc.prompt(bug=options.bug)
if not change_desc.description:
DieWithError("Description is empty. Aborting...")
message = change_desc.description
@@ -2660,6 +2660,29 @@ def _process_codereview_select_options(parser, options):
options.forced_codereview = 'rietveld'
+def _get_bug_line_value(prefix, bugs):
+ """Given prefix and comma separated list of bugs, returns a proper bug line.
+
+ Each bug can be either:
+ * a number, which is combined with prefix
+ * string, which is left as is.
+
+ >>> _get_bug_line_value('v8', '123,chromium:789')
+ 'v8:123,chromium:789'
Sergiy Byelozyorov 2016/07/01 14:41:12 I'd also check if each bug is in '\w+:\d+' format.
tandrii(chromium) 2016/07/01 15:27:04 Acknowledged.
+ """
+ def to_str(bug):
+ bug = bug.strip()
+ if not prefix:
+ return bug
+ try:
+ return '%s:%d' % (prefix, int(bug))
+ except ValueError:
+ return bug
+ return bug
Sergiy Byelozyorov 2016/07/01 14:41:12 Why is this necessary? You either return inside tr
tandrii(chromium) 2016/07/01 15:27:04 yep, leftover.
+ return ','.join(map(to_str, bugs.split(',')))
Sergiy Byelozyorov 2016/07/01 14:41:12 How about ', '.join(...)? Looks nicer for humans,
tandrii(chromium) 2016/07/01 15:27:04 Rietveld doens't care, neither does Gerrit. It's a
+
+
+
class ChangeDescription(object):
"""Contains a parsed form of the change description."""
R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$'
@@ -2735,7 +2758,7 @@ class ChangeDescription(object):
if new_tbr_line:
self.append_footer(new_tbr_line)
- def prompt(self):
+ def prompt(self, bug=None):
"""Asks the user to update the description."""
self.set_description([
'# Enter a description of the change.',
@@ -2747,7 +2770,10 @@ class ChangeDescription(object):
regexp = re.compile(self.BUG_LINE)
if not any((regexp.match(line) for line in self._description_lines)):
- self.append_footer('BUG=%s' % settings.GetBugPrefix())
+ prefix = settings.GetBugPrefix()
+ value = _get_bug_line_value(prefix, bug) if bug else prefix
+ # TODO(tandrii): change this to 'Bug: xxx' to be a proper Gerrit footer.
+ self.append_footer('BUG=%s' % value)
content = gclient_utils.RunEditor(self.description, True,
git_editor=settings.GetGitEditor())
if not content:
@@ -3725,6 +3751,9 @@ def CMDupload(parser, args):
parser.add_option('-f', action='store_true', dest='force',
help="force yes to questions (don't prompt)")
parser.add_option('-m', dest='message', help='message for patchset')
+ parser.add_option('-b', '--bug',
+ help='pre-populate the bug number(s) for this issue. '
+ 'If several, separate with commas')
parser.add_option('--message-file', dest='message_file',
help='file which contains message for patchset')
parser.add_option('-t', dest='title',
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698