rpm_ch: support '--all' and '--message' options.
authorwanchao-xu <wanchao.xu@samsung.com>
Fri, 19 Apr 2024 03:14:42 +0000 (11:14 +0800)
committerwanchao-xu <wanchao.xu@samsung.com>
Fri, 19 Apr 2024 03:22:57 +0000 (11:22 +0800)
Change-Id: Ia40b00566b07bb59975a1d2c6af4d44777cc07f1
Signed-off-by: wanchao-xu <wanchao.xu@samsung.com>
docs/manpages/gbp-rpm-ch.xml
gbp/scripts/rpm_ch.py

index e0f0d9d70a6c4a61138992031f2d2f05ebf332fe..ec23ee7cc67bbc125995e7d2c9ecfac91aa4dde1 100644 (file)
       <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>--all</option></arg>
+        <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>
           </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--all</option>
+        </term>
+        <listitem>
+          <para>
+          Use all commits from the Git history, overrides
+          <option>--since</option>.
+          </para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
         <term><option>--since=</option><replaceable>COMMITTISH</replaceable>
         </term>
           </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>--customizations=</option><replaceable>CUSTOMIZATION-FILE</replaceable>
         </term>
index 9cb99a25f9a13e0ff23484ac24ed484968e22eff..bb02e91e547b6a1d6b4f2ee4b6fd46419082a034 100644 (file)
@@ -223,7 +223,9 @@ def guess_commit(section, repo, options):
 
 def get_start_commit(changelog, repo, options):
     """Get the start commit from which to generate new entries"""
-    if options.since:
+    if options.all:
+        since = None
+    elif options.since:
         since = options.since
     else:
         if changelog.sections:
@@ -232,7 +234,7 @@ def get_start_commit(changelog, repo, options):
             since = None
         if not since:
             raise GbpError("Couldn't determine starting point from "
-                           "changelog, please use the '--since' option")
+                           "changelog, please use the '--since' or '--all' option")
         gbp.log.info("Continuing from commit '%s'" % since)
     return since
 
@@ -276,6 +278,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
@@ -359,6 +392,9 @@ def build_parser(name):
     # Range group options
     range_grp.add_option("-s", "--since", dest="since",
                          help="commit to start from (e.g. HEAD^^^, release/0.1.2)")
+    range_grp.add_option("--all", action="store_true",
+                         help="use all commits from the Git history, overrides "
+                         "--since")
     # Formatting group options
     format_grp.add_option("--no-release", action="store_false", default=True,
                           dest="release",
@@ -380,6 +416,10 @@ 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")
     return parser
 
 
@@ -419,26 +459,15 @@ 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'))
 
         # Do the actual update
-        entries = entries_from_commits(ch_file.changelog, repo, commits,
-                                       options)
+        entries = generate_new_entries(ch_file.changelog, repo, options, args)
         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])()
 
     except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: