Skip to content

Commit

Permalink
Merge pull request #3104 from Lex-2008/ENT-3638-changelog-title
Browse files Browse the repository at this point in the history
ENT-3638: Add commit title to changelog by default, if it has ticket …
  • Loading branch information
Lex-2008 committed Aug 8, 2018
2 parents 20a3eab + 3d28e0e commit 653953b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
6 changes: 4 additions & 2 deletions HACKING.md
Expand Up @@ -345,8 +345,9 @@ the behavior change which is important. This implies that refactorings that have
no visible effect on behavior don't need a changelog entry.

If a changelog entry is needed, your pull request should have at least one
commit with a "Changelog:" line in it, after the title. This may be one of the
following:
commit either with a "Changelog:" line in it (anywhere after the title), or
title should start with ticket number from our bug tracker ("CFE-1234").
"Changelog:" line may be one of the following:

* To write arbitrary message in the ChangeLog:
`Changelog: <message>`
Expand Down Expand Up @@ -453,3 +454,4 @@ and run
ln -s contrib/dir-locals.el .dir-locals.el

in the top directory of the source code checkout.

38 changes: 23 additions & 15 deletions misc/changelog-generator/changelog-generator
Expand Up @@ -20,13 +20,16 @@ LINKED_SHAS = {}
# messages.
SHA_TO_TRACKER = {}

# more relaxed regexp to find JIRA issues anywhere in commit message
JIRA_REGEX = r"(?:Jira:? *)?(?:https?://tracker.mender.io/browse/)?((?:CFE|ENT|INF|ARCHIVE|MEN|QA)-[0-9]+)"
# more strict regexp to find JIRA issues only in the beginning of title
JIRA_TITLE_REGEX = r"^(?:CFE|ENT|INF|ARCHIVE|MEN|QA)-[0-9]+"
TRACKER_REGEX = r"\(?(?:Ref:? *)?%s\)?:? *" % (JIRA_REGEX)

POSSIBLE_MISSED_TICKETS = {}

# Only for testing.
SORT_CHANGELOG = False
SORT_CHANGELOG = True

# Type of log to generate, this is bitwise.
LOG_TYPE = 0
Expand Down Expand Up @@ -107,47 +110,48 @@ else:

for repo in repos:
os.chdir(repo)
sha_list = subprocess.Popen(["git", "rev-list", "--reverse"] + sys.argv[1:], stdout=subprocess.PIPE)
sha_list = subprocess.Popen(
["git", "rev-list", "--no-merges", "--reverse"] + sys.argv[1:],
stdout=subprocess.PIPE)
for sha in sha_list.stdout:
sha = sha.decode().rstrip('\n')
blob = subprocess.Popen(["git", "cat-file", "-p", sha], stdout=subprocess.PIPE)
blob = subprocess.Popen(
["git", "log", "--format=%B", "-n", "1", sha],
stdout=subprocess.PIPE)

msg_started = False
title_fetched = False
title = ""
commit_msg = ""
log_entry_title = False
log_entry_commit = False
log_entry_local = False
log_entry = ""
for line in blob.stdout:
line = line.decode().rstrip('\r\n')
if line == "":
if not msg_started:
msg_started = True
continue

if log_entry:
add_entry(sha, log_entry)
log_entry = ""
if line == "" and log_entry:
add_entry(sha, log_entry)
log_entry = ""
log_entry_local = False

if not msg_started:
continue

# Tracker reference, remove from string.
for match in re.finditer(TRACKER_REGEX, line, re.IGNORECASE):
if not SHA_TO_TRACKER.get(sha):
SHA_TO_TRACKER[sha] = set()
SHA_TO_TRACKER[sha].add("".join(match.groups("")))
tracker_removed = re.sub(TRACKER_REGEX, "", line, flags=re.IGNORECASE)
line = tracker_removed.strip(' ')
tracker_removed = tracker_removed.strip(' ')
if re.match(JIRA_TITLE_REGEX, line) and not title_fetched:
log_entry_title = True
line = tracker_removed

if not title_fetched:
title = line
title_fetched = True

match = re.match("^ *Changelog: *(.*)", line, re.IGNORECASE)
if match:
log_entry_title = False
if log_entry:
add_entry(sha, log_entry)
log_entry = ""
Expand All @@ -157,6 +161,8 @@ for repo in repos:
log_entry = title
elif re.match("^Commit[ .]*$", match.group(1), re.IGNORECASE):
log_entry_commit = True
elif re.match("^None[ .]*$", match.group(1), re.IGNORECASE):
pass
else:
log_entry_local = True
log_entry = match.group(1)
Expand Down Expand Up @@ -211,6 +217,8 @@ for repo in repos:

blob.wait()

if log_entry_title:
add_entry(sha, title)
if log_entry_commit:
add_entry(sha, commit_msg)
if log_entry:
Expand Down
15 changes: 15 additions & 0 deletions misc/changelog-generator/test-changelog-generator
Expand Up @@ -330,6 +330,20 @@ Changelog: Make sure the bugtracker reference is taken from the title
################################################################################
git commit --allow-empty -m 'MEN-1234 with JIRA tag in title. N68
Title should be included, rest of commit - not'
################################################################################
git commit --allow-empty -m 'MEN-1234 with JIRA tag in title. N69
Changelog: None
Nothing should be included'
################################################################################
"$SRC_DIR/changelog-generator" --repo --sort-changelog HEAD > result.txt 2>stderr.txt || {
Expand Down Expand Up @@ -394,6 +408,7 @@ cat > expected.txt <<EOF
- This should be in changelog N8
And this N9
- This too. N33
- with JIRA tag in title. N68 (MEN-1234)
EOF
diff -u expected.txt result.txt
Expand Down

0 comments on commit 653953b

Please sign in to comment.