rel-eng/lib/spacewalk/releng/cli.py | 3 + rel-eng/lib/spacewalk/releng/tagger.py | 77 ++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 5 deletions(-)
New commits: commit 9b424fdb7e710feb73f0e458cdc88e75abbcab2e Author: James Bowes jbowes@redhat.com Date: Wed Mar 25 22:40:18 2009 -0400
Teach tito to let you use an editor on changelogs
An addendum to the previous patch; launch $EDITOR or vi to allow for modification to the changelog entry before commiting it.
diff --git a/rel-eng/lib/spacewalk/releng/tagger.py b/rel-eng/lib/spacewalk/releng/tagger.py index b56e71c..995402f 100644 --- a/rel-eng/lib/spacewalk/releng/tagger.py +++ b/rel-eng/lib/spacewalk/releng/tagger.py @@ -20,6 +20,8 @@ import sys import commands import StringIO import shutil +import subprocess +import tempfile import textwrap
from time import strftime @@ -128,28 +130,37 @@ class VersionTagger(object): (last_tag, "HEAD", ".") output = run_command(patch_command)
- print "No changelog entry found; adding the following for you:" - print - + fd, name = tempfile.mkstemp() + os.write(fd, "# No changelog entry found; please edit the following\n") header = "* %s %s <%s>\n" % (self.today, self.git_user, self.git_email)
- sys.stdout.write(header) - out_f.write(header) + os.write(fd, 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") + os.write(fd, "- ") + os.write(fd, "\n ".join(textwrap.wrap(cmd_out, 77))) + os.write(fd, "\n")
- sys.stdout.write("- ") - sys.stdout.write("\n ".join(textwrap.wrap(cmd_out, 77))) - sys.stdout.write("\n") + os.write(fd, "\n")
- out_f.write("\n") - sys.stdout.write("\n") + editor = 'vi' + if os.environ.has_key("EDITOR"): + editor = os.environ["EDITOR"]
- found_match = True + subprocess.call([editor, name]) + + os.lseek(fd, 0, 0) + file = os.fdopen(fd) + + for line in file.readlines(): + if not line.startswith("#"): + out_f.write(line) + + output = file.read() + + file.close() + os.unlink(name)
in_f.close() out_f.close()
commit a0d27856d488fd6837bf1db60e0dde0ab7899d64 Author: James Bowes jbowes@redhat.com Date: Wed Mar 25 21:13:13 2009 -0400
Teach tito to generate specfile changelog entries
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.
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.
spacewalk-commits@lists.fedorahosted.org