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>
Fri, 14 Nov 2014 12:47:19 +0000 (14:47 +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

index 6206e8841aab8039283c7be6747a360342ea6a8b..14683f37ae474187acb4048211e003d216962570 100755 (executable)
@@ -284,6 +284,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
@@ -404,6 +435,9 @@ def parse_args(argv):
                     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("--tag", action="store_true",
                     help="commit the changes and create a packaging/release"
@@ -440,26 +474,17 @@ 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, 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.tag: