From 4988ad1027d7742ea9b8a8882e65e3c2c2a96851 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 24 2016 05:14:13 +0000 Subject: [PATCH 1/2] Dont show merge commits Signed-off-by: Chenxiong Qi --- diff --git a/git-changelog b/git-changelog index 1879470..26d61cd 100755 --- a/git-changelog +++ b/git-changelog @@ -58,7 +58,7 @@ 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', '--no-merges', '--pretty=oneline', range], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() From 2ae555a1c457b28f5c4ca8ad11119aff1bfa8ab2 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 24 2016 05:14:13 +0000 Subject: [PATCH 2/2] Append fixed issue ids to each changelog Fix #85 This change tries to get fixed issue and bug IDs from commit message body as smart as possible. Maintainer should review the result and fix anything if necessary. Signed-off-by: Chenxiong Qi --- diff --git a/git-changelog b/git-changelog index 26d61cd..e53e14f 100755 --- a/git-changelog +++ b/git-changelog @@ -20,13 +20,11 @@ # Author: David Cantrell # Author: Brian C. Lane -import os import re import subprocess -import sys import textwrap -from optparse import OptionParser +from optparse import OptionParser class ChangeLog: @@ -53,6 +51,43 @@ class ChangeLog: return ret + def _extract_issue_ids(self, s): + prefix_pattern = re.compile(r'^(Fix|Fixes|Bug|Resolves?):? (.+)$', re.IGNORECASE) + prefix_match = prefix_pattern.match(s) + if prefix_match is None: + return + rest_s = prefix_match.groups()[1] + issue_ids = [] + for match in re.findall(r'(BZ|RHBZ|bz|rhbz)(:|: | )?(#?\d+)', rest_s): + issue_ids.append('{0}{1}'.format(match[0], match[2])) + if issue_ids: + # Sometimes, "BZ #1234" could confuse next step of search. So, + # remove them once found to avoid such confusion. + rest_s = re.sub(r'(BZ|RHBZ|bz|rhbz)(:|: | )?(#?\d+)', '', rest_s) + issue_ids.extend(re.findall(r'#?\d+', rest_s)) + issue_ids.sort() + return issue_ids + + def _get_fixed_issues(self, commit): + """Get fixed issue or bug IDs from commit message body + + Both patterns matching pagure issue and Bugzilla bug are supported. + Examples, + + Fix #1234 + Fixes: #11234 + Fixes: #11234 #9283 + Bug 123456 + Bug BZ123456 RHBZ123456 + """ + body = self._getCommitDetail(commit, "%b") + ids = None + for line in body: + ids = self._extract_issue_ids(line) + if ids: + break + return ids + def getLog(self): if not self.name: range = "%s.." % (self.version) @@ -77,10 +112,13 @@ class ChangeLog: commit = fields[0] summary = self._getCommitDetail(commit, "%s") - long = self._getCommitDetail(commit, "%b") author = self._getCommitDetail(commit, "%aE") + issue_ids = self._get_fixed_issues(commit) - log.append(("%s (%s)" % (summary.strip(), author))) + if issue_ids: + log.append(("%s - %s (%s)" % (summary.strip(), ' '.join(issue_ids), author))) + else: + log.append(("%s (%s)" % (summary.strip(), author))) return log @@ -96,6 +134,7 @@ class ChangeLog: return s + def main(): parser = OptionParser() parser.add_option("-n", "--name", dest="name", @@ -107,7 +146,6 @@ def main(): cl = ChangeLog(options.name, options.version) print(cl.formatLog()) + if __name__ == "__main__": main() - -