Skip to content

Commit b014201

Browse files
committed
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 <[email protected]>
1 parent 687b9af commit b014201

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

docs/manpages/gbp-rpm-ch.xml

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<arg><option>--message=</option><replaceable>MESSAGE</replaceable></arg>
3434
<arg><option>--since=</option><replaceable>COMMITISH</replaceable></arg>
3535
</group>
36+
<arg><option>--meta-bts=</option><replaceable>META_TAGS</replaceable></arg>
3637
<arg><option>--no-release</option></arg>
3738
<arg><option>--[no-]git-author</option></arg>
3839
<arg><option>--[no-]full</option></arg>
@@ -182,6 +183,19 @@
182183
</para>
183184
</listitem>
184185
</varlistentry>
186+
<varlistentry>
187+
<term><option>--meta-bts=</option><replaceable>META_TAGS</replaceable>
188+
</term>
189+
<listitem>
190+
<para>
191+
Meta tags in the commit messages that are interpreted as bug tracking
192+
system related references. The recognized bts references are added in
193+
the generated changelog entries. See the META TAGS section below for
194+
more information. The bts meta tag tracking feature can be disabled
195+
by defining an empty string.
196+
</para>
197+
</listitem>
198+
</varlistentry>
185199
<varlistentry>
186200
<term><option>--no-release</option>
187201
</term>
@@ -416,6 +430,8 @@
416430
<para>
417431
Indicate in the changelog entry that bug
418432
<replaceable>BUGNUMBER</replaceable> was addressed in this commit.
433+
The bts meta tags recognized by &gbp-rpm-ch; is actually defined by
434+
the <option>--meta-bts</option> option.
419435
</para>
420436
</listitem>
421437
</varlistentry>

gbp/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ class GbpOptionParserRpm(GbpOptionParser):
787787
'changelog-revision': '',
788788
'spawn-editor': 'always',
789789
'editor-cmd': 'vim',
790+
'meta-bts': '(Close|Closes|Fixes|Fix)',
790791
})
791792

792793
help = dict(GbpOptionParser.help)
@@ -848,6 +849,8 @@ class GbpOptionParserRpm(GbpOptionParser):
848849
'git-author':
849850
"Use name and email from git-config for the changelog header, "
850851
"default is '%(git-author)s'",
852+
'meta-bts':
853+
"Meta tags for the bts commands, default is '%(meta-bts)s'",
851854
})
852855

853856
def _warn_old_gbp_conf(self, gbp_conf):

gbp/rpm/policy.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class ChangelogEntryFormatter(object):
9494

9595
# Maximum length for a changelog entry line
9696
max_entry_line_length = 76
97-
# Bug tracking system related meta tags recognized from git commit msg
98-
bts_meta_tags = ("Close", "Closes", "Fixes", "Fix")
9997
# Regexp for matching bug tracking system ids (e.g. "bgo#123")
10098
bug_id_re = r'[A-Za-z0-9#_\-]+'
10199

@@ -107,15 +105,18 @@ def _parse_bts_tags(cls, lines, meta_tags):
107105
108106
@param lines: commit message
109107
@type lines: C{list} of C{str}
110-
@param meta_tags: meta tags to look for
111-
@type meta_tags: C{tuple} of C{str}
108+
@param meta_tags: meta tags (regexp) to look for
109+
@type meta_tags: C{str}
112110
@return: bts-ids per meta tag and the non-mathced lines
113111
@rtype: (C{dict}, C{list} of C{str})
114112
"""
113+
if not meta_tags:
114+
return ({}, lines[:])
115+
115116
tags = {}
116117
other_lines = []
117-
bts_re = re.compile(r'^(?P<tag>%s):\s*(?P<ids>.*)' %
118-
('|'.join(meta_tags)), re.I)
118+
bts_re = re.compile(r'^(?P<tag>%s):\s*(?P<ids>.*)' % meta_tags,
119+
re.I)
119120
bug_id_re = re.compile(cls.bug_id_re)
120121
for line in lines:
121122
match = bts_re.match(line)
@@ -172,7 +173,7 @@ def compose(cls, commit_info, **kwargs):
172173
return None
173174

174175
# Parse and filter out bts-related meta-tags
175-
bts_tags, body = cls._parse_bts_tags(body, cls.bts_meta_tags)
176+
bts_tags, body = cls._parse_bts_tags(body, kwargs['meta_bts'])
176177

177178
# Additional filtering
178179
body = cls._extra_filter(body, kwargs['ignore_re'])
@@ -191,7 +192,7 @@ def compose(cls, commit_info, **kwargs):
191192
text.extend([" " + line for line in body if line.strip()])
192193

193194
# Add bts tags and ids in the end
194-
for tag, ids in bts_tags.items():
195+
for tag, ids in sorted(bts_tags.items()):
195196
bts_msg = " (%s: %s)" % (tag, ', '.join(ids))
196197
if len(text[-1]) + len(bts_msg) >= cls.max_entry_line_length:
197198
text.append(" ")

gbp/scripts/rpm_ch.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def entries_from_commits(changelog, repo, commits, options):
286286
info = repo.get_commit_info(commit)
287287
entry_text = ChangelogEntryFormatter.compose(info, full=options.full,
288288
ignore_re=options.ignore_regex,
289-
id_len=options.idlen)
289+
id_len=options.idlen,
290+
meta_bts=options.meta_bts)
290291
if entry_text:
291292
entries.append(changelog.create_entry(author=info['author'].name,
292293
text=entry_text))
@@ -447,6 +448,7 @@ def build_parser(name):
447448
help="use all commits from the Git history, overrides "
448449
"--since")
449450
# Formatting group options
451+
format_grp.add_config_file_option(option_name="meta-bts", dest="meta_bts")
450452
format_grp.add_option("--no-release", action="store_false", default=True,
451453
dest="release",
452454
help="no release, just update the last changelog section")

tests/component/rpm/test_rpm_ch.py

+20
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ def test_branch_options(self):
173173

174174
eq_(mock_ch(['--packaging-branch=foo', '--ignore-branch']), 0)
175175

176+
def test_option_meta_bts(self):
177+
"""Test parsing of the bts meta tags"""
178+
repo = self.init_test_repo('gbp-test-native')
179+
180+
# Create a dummy commit that references bts
181+
with open('new-file', 'w') as fobj:
182+
fobj.write('foobar\n')
183+
repo.add_files('new-file')
184+
repo.commit_all('Fix\n\nCloses: #123\nFixes: #456\n Fixes: #789')
185+
186+
eq_(mock_ch(['--since=HEAD^']), 0)
187+
content = self.read_file('packaging/gbp-test-native.changes')
188+
# rpm-ch shouldn't have picked the ref with leading whitespace
189+
eq_(content[1], '- Fix (Closes: #123) (Fixes: #456)\n')
190+
191+
# Check the --meta-bts option
192+
eq_(mock_ch(['--since=HEAD^', '--meta-bts=Fixes']), 0)
193+
content = self.read_file('packaging/gbp-test-native.changes')
194+
eq_(content[1], '- Fix (Fixes: #456)\n')
195+
176196
def test_option_no_release(self):
177197
"""Test the --no-release cmdline option"""
178198
self.init_test_repo('gbp-test-native')

0 commit comments

Comments
 (0)