rpm-ch: add --message cmdline option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 26 Mar 2014 07:01:28 +0000 (09:01 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 3 Mar 2015 08:07:47 +0000 (10:07 +0200)
For giving the text for new changelog entry/entries, skipping git commit
messages entirely.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/rpm_ch.py
tests/component/rpm/test_rpm_ch.py

index 7a6c2bbe403f5668372b122850f5fe05d1754cdd..30426fb4097f572706b274db20c7219e17b79ae3 100755 (executable)
@@ -289,6 +289,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
@@ -426,6 +457,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")
@@ -478,27 +512,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:
index 177851c54691b78a91c6433871b4ee85e5edb8d2..810ea30ba529e410979f2191a5b4c2e567556222 100644 (file)
@@ -343,6 +343,17 @@ class TestRpmCh(RpmRepoTestBase):
         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')