From b14ee9bfae268d0e326cf3c4a790ef3115f640e3 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 6 Jun 2014 12:40:32 +0300 Subject: [PATCH] rpm-ch: implement --meta-bts option This gives the user the possibility to define what meta tags (in git commit message) gbp-rpm-ch recognizes as bug tracking system references. Alternatively, it makes it possible to disable bts meta tag parsing altogether. Signed-off-by: Markus Lehtonen --- docs/manpages/gbp-rpm-ch.xml | 16 ++++++++++++++++ gbp/config.py | 3 +++ gbp/rpm/policy.py | 17 +++++++++-------- gbp/scripts/rpm_ch.py | 4 +++- tests/component/rpm/test_rpm_ch.py | 20 ++++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/docs/manpages/gbp-rpm-ch.xml b/docs/manpages/gbp-rpm-ch.xml index b1fb17bf..b7cb47ce 100644 --- a/docs/manpages/gbp-rpm-ch.xml +++ b/docs/manpages/gbp-rpm-ch.xml @@ -33,6 +33,7 @@ MESSAGE COMMITISH + META_TAGS @@ -182,6 +183,19 @@ + + META_TAGS + + + + Meta tags in the commit messages that are interpreted as bug tracking + system related references. The recognized bts references are added in + the generated changelog entries. See the META TAGS section below for + more information. The bts meta tag tracking feature can be disabled + by defining an empty string. + + + @@ -416,6 +430,8 @@ Indicate in the changelog entry that bug BUGNUMBER was addressed in this commit. + The bts meta tags recognized by &gbp-rpm-ch; is actually defined by + the option. diff --git a/gbp/config.py b/gbp/config.py index 76a850de..b062248d 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -798,6 +798,7 @@ class GbpOptionParserRpm(GbpOptionParser): 'changelog-revision': '', 'spawn-editor': 'always', 'editor-cmd': 'vim', + 'meta-bts': '(Close|Closes|Fixes|Fix)', 'spec-vcs-tag': '', }) @@ -860,6 +861,8 @@ class GbpOptionParserRpm(GbpOptionParser): 'git-author': "Use name and email from git-config for the changelog header, " "default is '%(git-author)s'", + 'meta-bts': + "Meta tags for the bts commands, default is '%(meta-bts)s'", 'spec-vcs-tag': "Set/update the 'VCS:' tag in the spec file, empty value " "removes the tag entirely, default is '%(spec-vcs-tag)s'", diff --git a/gbp/rpm/policy.py b/gbp/rpm/policy.py index a027ed99..791b25b1 100644 --- a/gbp/rpm/policy.py +++ b/gbp/rpm/policy.py @@ -94,8 +94,6 @@ class ChangelogEntryFormatter(object): # Maximum length for a changelog entry line max_entry_line_length = 76 - # Bug tracking system related meta tags recognized from git commit msg - bts_meta_tags = ("Close", "Closes", "Fixes", "Fix") # Regexp for matching bug tracking system ids (e.g. "bgo#123") bug_id_re = r'[A-Za-z0-9#_\-]+' @@ -107,15 +105,18 @@ def _parse_bts_tags(cls, lines, meta_tags): @param lines: commit message @type lines: C{list} of C{str} - @param meta_tags: meta tags to look for - @type meta_tags: C{tuple} of C{str} + @param meta_tags: meta tags (regexp) to look for + @type meta_tags: C{str} @return: bts-ids per meta tag and the non-mathced lines @rtype: (C{dict}, C{list} of C{str}) """ + if not meta_tags: + return ({}, lines[:]) + tags = {} other_lines = [] - bts_re = re.compile(r'^(?P%s):\s*(?P.*)' % - ('|'.join(meta_tags)), re.I) + bts_re = re.compile(r'^(?P%s):\s*(?P.*)' % meta_tags, + re.I) bug_id_re = re.compile(cls.bug_id_re) for line in lines: match = bts_re.match(line) @@ -172,7 +173,7 @@ def compose(cls, commit_info, **kwargs): return None # Parse and filter out bts-related meta-tags - bts_tags, body = cls._parse_bts_tags(body, cls.bts_meta_tags) + bts_tags, body = cls._parse_bts_tags(body, kwargs['meta_bts']) # Additional filtering body = cls._extra_filter(body, kwargs['ignore_re']) @@ -191,7 +192,7 @@ def compose(cls, commit_info, **kwargs): text.extend([" " + line for line in body if line.strip()]) # Add bts tags and ids in the end - for tag, ids in bts_tags.items(): + for tag, ids in sorted(bts_tags.items()): bts_msg = " (%s: %s)" % (tag, ', '.join(ids)) if len(text[-1]) + len(bts_msg) >= cls.max_entry_line_length: text.append(" ") diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 29dc54fa..a60ba96f 100644 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -286,7 +286,8 @@ def entries_from_commits(changelog, repo, commits, options): info = repo.get_commit_info(commit) entry_text = ChangelogEntryFormatter.compose(info, full=options.full, ignore_re=options.ignore_regex, - id_len=options.idlen) + id_len=options.idlen, + meta_bts=options.meta_bts) if entry_text: entries.append(changelog.create_entry(author=info['author'].name, text=entry_text)) @@ -447,6 +448,7 @@ def build_parser(name): help="use all commits from the Git history, overrides " "--since") # Formatting group options + format_grp.add_config_file_option(option_name="meta-bts", dest="meta_bts") format_grp.add_option("--no-release", action="store_false", default=True, dest="release", help="no release, just update the last changelog section") diff --git a/tests/component/rpm/test_rpm_ch.py b/tests/component/rpm/test_rpm_ch.py index e640bb01..197f6db9 100644 --- a/tests/component/rpm/test_rpm_ch.py +++ b/tests/component/rpm/test_rpm_ch.py @@ -173,6 +173,26 @@ def test_branch_options(self): eq_(mock_ch(['--packaging-branch=foo', '--ignore-branch']), 0) + def test_option_meta_bts(self): + """Test parsing of the bts meta tags""" + repo = self.init_test_repo('gbp-test-native') + + # Create a dummy commit that references bts + with open('new-file', 'w') as fobj: + fobj.write('foobar\n') + repo.add_files('new-file') + repo.commit_all('Fix\n\nCloses: #123\nFixes: #456\n Fixes: #789') + + eq_(mock_ch(['--since=HEAD^']), 0) + content = self.read_file('packaging/gbp-test-native.changes') + # rpm-ch shouldn't have picked the ref with leading whitespace + eq_(content[1], '- Fix (Closes: #123) (Fixes: #456)\n') + + # Check the --meta-bts option + eq_(mock_ch(['--since=HEAD^', '--meta-bts=Fixes']), 0) + content = self.read_file('packaging/gbp-test-native.changes') + eq_(content[1], '- Fix (Fixes: #456)\n') + def test_option_no_release(self): """Test the --no-release cmdline option""" self.init_test_repo('gbp-test-native')