If tito doesn't find a changelog entry in the specfile during a tag
operation, he can now create one himself from the git logs. The entry
line items are made from the subject and email of committer for all
untagged commits of the package in question.

If you don't like tito doing your work for you, you can stop him from
doing so by passing --no-auto-changelog on the command line.
---

Good job on tito + git, guys. This was way easier than I thought it was
going to be. 

-James

 rel-eng/lib/spacewalk/releng/cli.py    |    3 +
 rel-eng/lib/spacewalk/releng/tagger.py |   66 +++++++++++++++++++++++++++++--
 2 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/rel-eng/lib/spacewalk/releng/cli.py 
b/rel-eng/lib/spacewalk/releng/cli.py
index d46d0d3..9105678 100644
--- a/rel-eng/lib/spacewalk/releng/cli.py
+++ b/rel-eng/lib/spacewalk/releng/cli.py
@@ -413,6 +413,9 @@ class TagModule(BaseCliModule):
                 action="store_true",
                 help="Use spec file version/release exactly as specified in 
spec file to tag package.")
 
+        self.parser.add_option("--no-auto-changelog", action="store_true",
+                default=False,
+                help="Don't automatically create a changelog entry for this 
tag if none is found")
 
     def main(self):
         BaseCliModule.main(self)
diff --git a/rel-eng/lib/spacewalk/releng/tagger.py 
b/rel-eng/lib/spacewalk/releng/tagger.py
index 186b7d6..b56e71c 100644
--- a/rel-eng/lib/spacewalk/releng/tagger.py
+++ b/rel-eng/lib/spacewalk/releng/tagger.py
@@ -19,6 +19,8 @@ import re
 import sys
 import commands
 import StringIO
+import shutil
+import textwrap
 
 from time import strftime
 
@@ -54,6 +56,8 @@ class VersionTagger(object):
         self.changelog_regex = re.compile('\\*\s%s\s%s(\s<%s>)?' % (self.today,
             self.git_user, self.git_email))
 
+        self._no_auto_changelog = False
+
     def run(self, options):
         """
         Perform the actions requested of the tagger.
@@ -63,6 +67,8 @@ class VersionTagger(object):
         """
         if options.tag_release:
             print("WARNING: --tag-release option no longer necessary, 'tito 
tag' will accomplish the same thing.")
+        if options.no_auto_changelog:
+            self._no_auto_changelog=True
         self._tag_release()
 
     def _tag_release(self):
@@ -92,14 +98,64 @@ class VersionTagger(object):
         f.close()
 
         if not found_changelog:
-            # TODO: Instead of dying here, we could try to add one 
automatically
-            # and generate the changelog entries from the first line of the 
git commit
-            # history for all commits since the last package version was 
tagged.
-            error_out("No changelog entry found: '* %s %s <%s>'" % (
-                self.today, self.git_user, self.git_email))
+            if self._no_auto_changelog:
+                error_out("No changelog entry found: '* %s %s <%s>'" % (
+                    self.today, self.git_user, self.git_email))
+            else:
+                self._make_changelog()
         else:
             debug("Found changelog entry.")
 
+    def _make_changelog(self):
+        """
+        Create a new changelog entry in the spec, with line items from git
+        """
+        in_f = open(self.spec_file, 'r')
+        out_f = open(self.spec_file + ".new", 'w')
+
+        found_changelog = False
+        for line in in_f.readlines():
+            out_f.write(line)
+
+            if not found_changelog and line.startswith("%changelog"):
+                found_changelog = True
+
+                old_version = get_latest_tagged_version(self.project_name)
+                last_tag = "%s-%s" % (self.project_name, old_version)
+                patch_command = \
+                        "git log --pretty=format:%%s\ \(%%ae\)" \
+                        " --relative %s..%s -- %s" % \
+                        (last_tag, "HEAD", ".")
+                output = run_command(patch_command)
+
+                print "No changelog entry found; adding the following for you:"
+                print
+
+                header = "* %s %s <%s>\n" % (self.today, self.git_user,
+                        self.git_email)
+
+                sys.stdout.write(header)
+                out_f.write(header)
+
+                for cmd_out in output.split("\n"):
+                    out_f.write("- ")
+                    out_f.write("\n  ".join(textwrap.wrap(cmd_out, 77)))
+                    out_f.write("\n")
+
+                    sys.stdout.write("- ")
+                    sys.stdout.write("\n  ".join(textwrap.wrap(cmd_out, 77)))
+                    sys.stdout.write("\n")
+
+                out_f.write("\n")
+                sys.stdout.write("\n")
+
+                found_match = True
+
+        in_f.close()
+        out_f.close()
+
+        shutil.move(self.spec_file + ".new", self.spec_file)
+
     def _update_changelog(self, new_version):
         """
         Update the changelog with the new version.
-- 
1.6.2.1.569.g10bb7

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to