Improve and refactor push-to-trunk script.

Let change log formatter squash title and bug reference. Repair wrongly indented first line in change log. Add automatic rietveld reload of commit messages to enable late corrections.

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/83603002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18057 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 253d1550
......@@ -99,8 +99,8 @@ def MakeChangeLogBody(commit_messages, auto_format=False):
result = ""
added_titles = set()
for (title, body, author) in commit_messages:
# TODO(machenbach): Reload the commit description from rietveld in order to
# catch late changes.
# TODO(machenbach): Better check for reverts. A revert should remove the
# original CL from the actual log entry.
title = title.strip()
if auto_format:
# Only add commits that set the LOG flag correctly.
......@@ -114,16 +114,12 @@ def MakeChangeLogBody(commit_messages, auto_format=False):
if title in added_titles:
continue
# TODO(machenbach): Let python do all formatting. Get raw git title, attach
# issue and add/move dot to the end - all in one line. Make formatting and
# indentation afterwards.
# Add the commit's title line.
result += "%s\n" % Fill80(title)
# Add and format the commit's title and bug reference. Move dot to the end.
added_titles.add(title)
# Add bug references.
result += MakeChangeLogBugReference(body)
raw_title = re.sub(r"(\.|\?|!)$", "", title)
bug_reference = MakeChangeLogBugReference(body)
space = " " if bug_reference else ""
result += "%s\n" % Fill80("%s%s%s." % (raw_title, space, bug_reference))
# Append the commit's author for reference if not in auto-format mode.
if not auto_format:
......@@ -169,8 +165,7 @@ def MakeChangeLogBugReference(body):
FormatIssues("Chromium ", crbugs)
if len(bug_groups) > 0:
# Format with 8 characters indentation and max 80 character lines.
return "%s\n" % Fill80("(%s)" % ", ".join(bug_groups))
return "(%s)" % ", ".join(bug_groups)
else:
return ""
......
......@@ -30,6 +30,7 @@ import datetime
import optparse
import sys
import tempfile
import urllib2
from common_includes import *
......@@ -91,6 +92,21 @@ class DetectLastPush(Step):
class PrepareChangeLog(Step):
MESSAGE = "Prepare raw ChangeLog entry."
def Reload(self, body):
"""Attempts to reload the commit message from rietveld in order to allow
late changes to the LOG flag. Note: This is brittle to future changes of
the web page name or structure.
"""
match = re.search(r"^Review URL: https://codereview\.chromium\.org/(\d+)$",
body, flags=re.M)
if match:
cl_url = "https://codereview.chromium.org/%s/description" % match.group(1)
try:
body = self.ReadURL(cl_url)
except urllib2.URLError:
pass
return body
def RunStep(self):
self.RestoreIfUnset("last_push")
......@@ -112,7 +128,7 @@ class PrepareChangeLog(Step):
commit_messages = [
[
self.Git("log -1 %s --format=\"%%s\"" % commit),
self.Git("log -1 %s --format=\"%%B\"" % commit),
self.Reload(self.Git("log -1 %s --format=\"%%B\"" % commit)),
self.Git("log -1 %s --format=\"%%an\"" % commit),
] for commit in commits.splitlines()
]
......@@ -151,6 +167,7 @@ class EditChangeLog(Step):
changelog_entry = FileToText(self.Config(CHANGELOG_ENTRY_FILE)).rstrip()
changelog_entry = StripComments(changelog_entry)
changelog_entry = "\n".join(map(Fill80, changelog_entry.splitlines()))
changelog_entry = changelog_entry.lstrip()
if changelog_entry == "":
self.Die("Empty ChangeLog entry.")
......@@ -541,6 +558,12 @@ def ProcessOptions(options):
if options.s < 0:
print "Bad step number %d" % options.s
return False
if options.f and not options.r:
print "A reviewer (-r) is required in forced mode."
return False
if options.f and not options.c:
print "A chromium checkout (-c) is required in forced mode."
return False
return True
......
This diff is collapsed.
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