Pull back the changelog generation to the simplest thing that can possibly work

This commit is contained in:
Alex Young
2014-02-25 17:24:25 +00:00
parent 2fa1ce8e6b
commit ffa45879d7
3 changed files with 7 additions and 579 deletions

127
Rakefile
View File

@@ -51,127 +51,10 @@ end
desc "Remove all build targets, binaries and temporary files"
maketask :clean
# If you've made a commit, the changelog needs redoing
file "debian/changelog" => ".hg/last-message.txt" do
latesttag_cmd = "hg log -l1 --template '{latesttag}'"
latesttag = `#{latesttag_cmd}`.strip
log_cmd = "hg log --style xml"
projname = "flexnbd"
File.open("debian/changelog", "w") do |changelog|
IO.popen( log_cmd, "r" ) do |io|
listener = HGChangelog::Listener.new changelog, projname, latesttag
REXML::Document.parse_stream io, listener
io.close
end
end
file "debian/changelog" do
FileUtils.mkdir_p "debian"
sh "hg log --style=changelog.template > debian/changelog"
end
desc "Generate the changelog"
task :changelog => "debian/changelog"
BEGIN {
require 'rexml/document'
require 'date'
require 'erb'
module HGChangelog
class ChangelogEntry
attr_accessor :email
attr_accessor :author_name
attr_accessor :date
def initialize(projname, tag, rev)
@projname = projname
@tag = tag
@rev = rev
@lines = []
end
def close( stream )
stream.write self.to_s
end
def <<( msg )
@lines << msg
end
def to_s
if @lines.empty?
""
else
template = <<-TEMPLATE
<%= @projname %> (<%= @tag %>-<%= @rev %>) stable; urgency=low
<% for line in @lines -%>
* <%= line.split("\n").first.strip %>
<% end -%>
-- <%= @author_name %> <<%= @email %>> <%= render_date %>
TEMPLATE
ERB.new(template, nil, "-").result(binding)
end
end
def render_date
DateTime.parse(@date).rfc2822
end
end # class ChangelogEntry
class Listener
def initialize out, projname, start_tag
@out = out
@projname = projname
@start_tag = start_tag
end
def method_missing(sym,*args,&blk)
end
def tag_start( name, attrs )
case name
when "logentry"
@rev = attrs['revision']
if !@entry # first time; collect stuffs for everything since last tag
@entry = ChangelogEntry.new @projname, @start_tag, @rev
end
when "author"
@email = attrs['email']
when "tag"
@entry.close @out if @entry
@tagged = true
end
end
def tag_end( name )
case name
when "logentry"
if @tagged
@entry.email = @email
@entry.author_name = @author_name
@entry.date = @date
end
@entry << @message if @message !~ /Added tag.*for changeset/
@tagged = false
when "author"
@author_name = @text
when "tag"
if @text != "tip" # again, we want to skip the first one
@entry = ChangelogEntry.new @projname, @text, @rev
end
when "msg"
@message = @text
when "date"
@date = @text
when "log"
@entry.close @out
end
end
def text( text )
@text = text
end
end # class Listener
end # module HGChangelog
}