Skip to content

Commit

Permalink
rpm-ch: add --message cmdline option
Browse files Browse the repository at this point in the history
This option can be used to directly give the text for new changelog
entry, skipping auto-generation from git commit history entirely. Thus,
'--since' or '--all' do not have any effect when '--message' is defined.

Signed-off-by: Markus Lehtonen <[email protected]>
  • Loading branch information
marquiz committed Jan 22, 2018
1 parent 7e47303 commit 91fc213
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
16 changes: 15 additions & 1 deletion docs/manpages/gbp-rpm-ch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
<arg><option>--packaging-dir=</option><replaceable>DIRECTORY</replaceable></arg>
<arg><option>--changelog-file=</option><replaceable>FILEPATH</replaceable></arg>
<arg><option>--spec-file=</option><replaceable>FILEPATH</replaceable></arg>
<arg><option>--since=</option><replaceable>COMMITISH</replaceable></arg>
<group>
<arg><option>--message=</option><replaceable>MESSAGE</replaceable></arg>
<arg><option>--since=</option><replaceable>COMMITISH</replaceable></arg>
</group>
<arg><option>--no-release</option></arg>
<arg><option>--[no-]git-author</option></arg>
<arg><option>--[no-]full</option></arg>
Expand Down Expand Up @@ -270,6 +273,17 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--message=<replaceable>MESSAGE</replaceable></option>
</term>
<listitem>
<para>
Text to use for new changelog entries. Git history and the commit
messages, including <option>--since</option> and
<option>--all</option> options are ignored in this case.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--commit</option>
</term>
Expand Down
49 changes: 37 additions & 12 deletions gbp/scripts/rpm_ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,37 @@ def entries_from_commits(changelog, repo, commits, options):
return entries


def entries_from_text(changelog, text, author):
"""Generate a list of changelog entries from a string"""
entries = []
# Use current user as the author for all entries
for line in text.splitlines():
if line.strip():
entry_text = "- %s" % line.strip()
entries.append(changelog.create_entry(author=author,
text=entry_text))
return entries


def generate_new_entries(changelog, repo, options, args):
"""Generate new entries to be appended to changelog"""
if options.message:
author = get_author(repo, options.git_author)[0]
entries = entries_from_text(changelog, options.message, author)
else:
# Get range of commits from where to generate changes
since = get_start_commit(changelog, repo, options)
if args:
gbp.log.info("Only looking for changes in '%s'" % ", ".join(args))
commits = repo.get_commits(since=since, until='HEAD', paths=args,
options=options.git_log.split(" "))
commits.reverse()
if not commits:
gbp.log.info("No changes detected from %s to %s." % (since, 'HEAD'))
entries = entries_from_commits(changelog, repo, commits, options)
return entries


def update_changelog(changelog, entries, repo, spec, options):
"""Update the changelog with a range of commits"""
# Get info for section header
Expand Down Expand Up @@ -431,6 +462,9 @@ def build_parser(name):
dest="spawn_editor")
format_grp.add_config_file_option(option_name="editor-cmd",
dest="editor_cmd")
format_grp.add_option("-m", '--message',
help="text to use as new changelog entries - git commit "
"messages and the --since are ignored in this case")
# Commit/tag group options
commit_grp.add_option("-c", "--commit", action="store_true",
help="commit changes")
Expand Down Expand Up @@ -485,27 +519,18 @@ def main(argv):

# Find and parse changelog file
ch_file = parse_changelog_file(repo, spec, options)
since = get_start_commit(ch_file.changelog, repo, options)

# Get range of commits from where to generate changes
if args:
gbp.log.info("Only looking for changes in '%s'" % ", ".join(args))
commits = repo.get_commits(since=since, until='HEAD', paths=args,
options=options.git_log.split(" "))
commits.reverse()
if not commits:
gbp.log.info("No changes detected from %s to %s." % (since, 'HEAD'))
# Get new entries
entries = generate_new_entries(ch_file.changelog, repo, options, args)

# Do the actual update
entries = entries_from_commits(ch_file.changelog, repo, commits,
options)
tag, tag_msg, author, committer = update_changelog(ch_file.changelog,
entries, repo, spec,
options)
# Write to file
ch_file.write()

if editor_cmd:
if editor_cmd and not options.message:
gbpc.Command(editor_cmd, [ch_file.path])()

if options.commit:
Expand Down
11 changes: 11 additions & 0 deletions tests/component/rpm/test_rpm_ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ def test_option_editor_cmd(self):
eq_(mock_ch(['--spawn-editor=always', '--editor-cmd=']),
0)

def test_option_message(self):
"""Test the --message cmdline option"""
self.init_test_repo('gbp-test-native')
orig_content = self.read_file('packaging/gbp-test-native.changes')

eq_(mock_ch(['--message', 'my entry\nanother entry']), 0)
content = self.read_file('packaging/gbp-test-native.changes')
# Added header, two entries and a blank line
eq_(len(content), len(orig_content) + 4)
eq_(content[2], '- another entry\n')

def test_user_customizations(self):
"""Test the user customizations"""
repo = self.init_test_repo('gbp-test-native')
Expand Down

0 comments on commit 91fc213

Please sign in to comment.