Add --issues and --issue_numbers to gitlog2asciidoc.py
The --issues option can be used to only output the commits with issues associated with them. The --issue_numbers only outputs the actual issue numbers of the commits with issues associated with them. Change-Id: Icf1c03461fa8054c6ae75e66ef80d403cc7052bc
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
"""
|
||||
This script generates a release note from the output of git log
|
||||
between the specified tags.
|
||||
|
||||
Options:
|
||||
--issues Show output the commits with issues associated with them.
|
||||
--issue-numbers Show outputs issue numbers of the commits with issues
|
||||
associated with them
|
||||
|
||||
Arguments:
|
||||
since -- tag name
|
||||
until -- tag name
|
||||
@@ -28,9 +34,26 @@ Expected Output:
|
||||
<commit message>
|
||||
"""
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit('Usage: ' + sys.argv[0] + ' <since> <until>')
|
||||
since_until = sys.argv[1] + '..' + sys.argv[2]
|
||||
parser = OptionParser(usage='usage: %prog [options] <since> <until>')
|
||||
|
||||
parser.add_option('-i', '--issues', action='store_true',
|
||||
dest='issues_only', default=False,
|
||||
help='only output the commits with issues association')
|
||||
|
||||
parser.add_option('-n', '--issue-numbers', action='store_true',
|
||||
dest='issue_numbers_only', default=False,
|
||||
help='only outputs issue numbers of the commits with \
|
||||
issues association')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if len(args) != 2:
|
||||
parser.error("wrong number of arguments")
|
||||
|
||||
issues_only = options.issues_only
|
||||
issue_numbers_only = options.issue_numbers_only
|
||||
|
||||
since_until = args[0] + '..' + args[1]
|
||||
proc = subprocess.Popen(['git', 'log', '--reverse', '--no-merges',
|
||||
since_until, "--format=* %s%n+%n%b"],
|
||||
stdout=subprocess.PIPE,
|
||||
@@ -40,45 +63,45 @@ stdout_value = proc.communicate()[0]
|
||||
|
||||
subject = ""
|
||||
message = []
|
||||
is_issue = False
|
||||
|
||||
# regex pattern to match following cases such as Bug: 123, Issue Bug: 123, Bug: GERRIT-123,
|
||||
# Bug: issue 123, Bug issue: 123, issue: 123, issue: bug 123
|
||||
# regex pattern to match following cases such as Bug: 123, Issue Bug: 123,
|
||||
# Bug: GERRIT-123, Bug: issue 123, Bug issue: 123, issue: 123, issue: bug 123
|
||||
p = re.compile('bug: GERRIT-|bug(:? issue)?:? |issue(:? bug)?:? ',
|
||||
re.IGNORECASE)
|
||||
|
||||
for line in stdout_value.splitlines(True):
|
||||
|
||||
# Move issue number to subject line
|
||||
if p.match(line):
|
||||
line = p.sub('issue ', line).replace('\n',' ')
|
||||
subject = subject[:2] + line + subject[2:]
|
||||
|
||||
elif re.match('\* ', line) >= 0:
|
||||
# Write change log for a commit
|
||||
if subject != "":
|
||||
# Write subject
|
||||
sys.stdout.write(subject)
|
||||
|
||||
# Write message lines
|
||||
if message != []:
|
||||
# Clear + from last line in commit message
|
||||
message[-1] = '\n'
|
||||
for m in message:
|
||||
sys.stdout.write(m)
|
||||
|
||||
# Start new commit block
|
||||
message = []
|
||||
subject = line
|
||||
continue
|
||||
|
||||
# Remove commit footers
|
||||
elif re.match(r'((\w+-)+\w+:)', line) is not None:
|
||||
continue
|
||||
|
||||
else:
|
||||
if line == '\n':
|
||||
# Don't add extra blank line if last one is already blank
|
||||
if message != [] and message[-1] != '+\n':
|
||||
if issue_numbers_only:
|
||||
for line in stdout_value.splitlines(True):
|
||||
if p.match(line):
|
||||
sys.stdout.write(p.sub('', line))
|
||||
else:
|
||||
for line in stdout_value.splitlines(True):
|
||||
# Move issue number to subject line
|
||||
if p.match(line):
|
||||
line = p.sub('issue ', line).replace('\n',' ')
|
||||
subject = subject[:2] + line + subject[2:]
|
||||
is_issue = True
|
||||
elif line.startswith('* '):
|
||||
# Write change log for a commit
|
||||
if subject != "":
|
||||
if (not issues_only or is_issue):
|
||||
# Write subject
|
||||
sys.stdout.write(subject)
|
||||
# Write message lines
|
||||
if message != []:
|
||||
# Clear + from last line in commit message
|
||||
message[-1] = '\n'
|
||||
for m in message:
|
||||
sys.stdout.write(m)
|
||||
# Start new commit block
|
||||
message = []
|
||||
subject = line
|
||||
is_issue = False
|
||||
# Remove commit footers
|
||||
elif re.match(r'((\w+-)+\w+:)', line):
|
||||
continue
|
||||
# Don't add extra blank line if last one is already blank
|
||||
elif line == '\n' and message and message[-1] != '+\n':
|
||||
message.append('+\n')
|
||||
else:
|
||||
elif line != '\n':
|
||||
message.append(line)
|
||||
|
Reference in New Issue
Block a user