Fix changelog generator script
* Correctly exclude merge commits (there's a git log option for it) * Stop mangling log lines with @ symbol. This should only be cut for author of a change. * Fix PEP8 issues * Remove unused code * Port to argparse (optparse is deprecated) Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
0cdf996e6e
commit
3a59e8f266
@ -20,20 +20,15 @@
|
||||
# Author: David Cantrell <dcantrell@redhat.com>
|
||||
# Author: Brian C. Lane <bcl@redhat.com>
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
from optparse import OptionParser
|
||||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
|
||||
class ChangeLog:
|
||||
def __init__(self, name, version):
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.ignore = None
|
||||
|
||||
def _getCommitDetail(self, commit, field):
|
||||
proc = subprocess.Popen(['git', 'log', '-1',
|
||||
@ -43,7 +38,7 @@ class ChangeLog:
|
||||
|
||||
ret = proc[0].strip('\n').split('\n')
|
||||
|
||||
if len(ret) == 1 and ret[0].find('@') != -1:
|
||||
if field == '%aE' and len(ret) == 1 and ret[0].find('@') != -1:
|
||||
ret = ret[0].split('@')[0]
|
||||
elif len(ret) == 1:
|
||||
ret = ret[0]
|
||||
@ -57,25 +52,19 @@ class ChangeLog:
|
||||
range = "%s.." % (self.version)
|
||||
else:
|
||||
range = "%s-%s.." % (self.name, self.version)
|
||||
proc = subprocess.Popen(['git', 'log', '--pretty=oneline', range],
|
||||
proc = subprocess.Popen(['git', 'log', '--pretty=oneline',
|
||||
'--no-merges', range],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE).communicate()
|
||||
lines = filter(lambda x: x.find('l10n: ') != 41 and \
|
||||
x.find('Merge commit') != 41 and \
|
||||
x.find('Merge branch') != 41,
|
||||
lines = filter(lambda x: x.find('l10n: ') != 41,
|
||||
proc[0].strip('\n').split('\n'))
|
||||
|
||||
if self.ignore and self.ignore != '':
|
||||
for commit in self.ignore.split(','):
|
||||
lines = filter(lambda x: not x.startswith(commit), lines)
|
||||
|
||||
log = []
|
||||
for line in lines:
|
||||
fields = line.split(' ')
|
||||
commit = fields[0]
|
||||
|
||||
summary = self._getCommitDetail(commit, "%s")
|
||||
long = self._getCommitDetail(commit, "%b")
|
||||
author = self._getCommitDetail(commit, "%aE")
|
||||
|
||||
log.append(("%s (%s)" % (summary.strip(), author)))
|
||||
@ -94,18 +83,17 @@ class ChangeLog:
|
||||
|
||||
return s
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
parser.add_option("-n", "--name", dest="name",
|
||||
help="Name of package used in tags")
|
||||
parser.add_option("-v", "--version", dest="version",
|
||||
help="Last version, changelog is commits after this tag")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
cl = ChangeLog(options.name, options.version)
|
||||
def main():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-n", "--name",
|
||||
help="Name of package used in tags")
|
||||
parser.add_argument("-v", "--version",
|
||||
help="Last version, changelog is commits after this tag")
|
||||
args = parser.parse_args()
|
||||
|
||||
cl = ChangeLog(args.name, args.version)
|
||||
print cl.formatLog()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user