Created
October 4, 2010 13:36
-
-
Save nagachika/609688 to your computer and use it in GitHub Desktop.
ruby-changes.rb - create template for ruby-trunk-changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
module Svn | |
class Revision | |
def initialize(str) | |
unless /r(\d+) \| (\S+) \| (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \S+)/ =~ str | |
raise "unrecognized svn log message #{str}" | |
end | |
@revision = Regexp.last_match(1) | |
@developer = Regexp.last_match(2) | |
@time = Regexp.last_match(3) | |
@revision = Integer(@revision) | |
@msg = str.split(/\n/)[2..-1].join("\n") | |
end | |
attr_reader :revision, :developer, :time, :msg | |
end | |
module Log | |
def format_time(time) | |
"{\"#{time.strftime("%Y-%m-%d %H:%M:%S")}\"}" | |
end | |
module_function :format_time | |
def revisions(root, from, to="HEAD", branch="trunk") | |
if from.is_a?(Time) | |
from = format_time(from) | |
end | |
if to.is_a?(Time) | |
to = format_time(to) | |
end | |
msg = `svn log --revision #{from}:#{to} #{root}/#{branch}` | |
revs = msg.split(/^-{72}$/).select{|l| /\S+/ =~ l } | |
revs.map{|msg| Revision.new(msg) } | |
end | |
module_function :revisions | |
end | |
end | |
def revisions(config, from, to="HEAD") | |
Svn::Log.revisions(config[:root], from, to, config[:branch] || "trunk") | |
end | |
def viewvc_uri(revision) | |
"http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=#{revision}" | |
end | |
def filter_anchor(msg) | |
[ | |
[ /\[ruby-dev:(\d+)\]/, '<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/\\1">\\0</a>' ], | |
[ /\[ruby-list:(\d+)\]/, '<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/\\1">\\0</a>' ], | |
[ /\[ruby-core:(\d+)\]/, '<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/\\1">\\0</a>' ], | |
[ /\[ruby-talk:(\d+)\]/, '<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/\\1">\\0</a>' ], | |
[ /\[Bug #(\d+)\]/, '<a href="http://redmine.ruby-lang.org/issues/show/\\1">\\0</a>' ], | |
[ /^\s*\*/, "-" ], | |
].each do |pat, sub| | |
msg.gsub!(pat, sub) | |
end | |
msg | |
end | |
def create_template(port, config, from, opt={}) | |
revs = revisions(config, from, opt[:to] || "HEAD") | |
unless revs.empty? | |
r1 = revs[0].revision | |
r2 = revs[-1].revision | |
port << "*ruby_trunk_changes_#{r1}_#{r2}*[ruby][changes]ruby-trunk-changes r#{r1} - r#{r2}\n" | |
port << "\n" | |
revs.each do |rev| | |
port << "** %s:<a href=\"%s\">r%d %s</a>\n" % [rev.developer, viewvc_uri(rev.revision), rev.revision, rev.time] | |
port << filter_anchor(rev.msg) | |
port << "\n\n" | |
end | |
end | |
end | |
config = { | |
:root => "http://svn.ruby-lang.org/repos/ruby", | |
:branch => "trunk", | |
} | |
if ARGV[0] | |
from = Integer(ARGV[0]) | |
else | |
from = Time.now - 24 * 60 * 60 | |
end | |
create_template($stdout, config, from) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment