Created
July 21, 2008 20:00
-
-
Save huikau/67 to your computer and use it in GitHub Desktop.
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
# just thought it would be funny to post a Subversion related thingy on a Git site... (github == pretty durn kewl) | |
require 'webrick' | |
require 'optparse' | |
require 'rubygems' | |
require 'rscm' # jruby -S gem install rscm | |
TEMPLATE = <<-EOS | |
<?xml version="1.0" encoding="UTF-8"?> | |
<rss version="2.0" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
> | |
<channel> | |
<title>SVN Log feed for : <%= repo.url %></title> | |
<link><%= repo.url %></link> | |
<description>SVN Log feed for : <%= repo.url %></description> | |
<language>en-us</language> | |
<copyright><%= repo.url %></copyright> | |
<generator>rscm</generator> | |
<% revs.each do |rev| %> | |
<item> | |
<title>Revision <%= rev.identifier %> by <%= rev.developer %></title> | |
<pubDate><%= rev.time.to_rfc2822 %></pubDate> | |
<guid isPermaLink="false"><%= rev.identifier %></guid> | |
<author><%= rev.developer %></author> | |
<description disable-output-escaping="yes"> | |
Revision: <%= rev.identifier %><br/> | |
Developer: <%= rev.developer %><br/> | |
Date: <%= rev.time %> | |
<br/> | |
<br/> | |
<% if rev.message != '' && !rev.message != nil %> | |
Log Message: <%= rev.message %> | |
<% else %> | |
[[No Log Message]] | |
<% end %> | |
<br/> | |
<br/> | |
Files: | |
<table> | |
<% rev.each do |file| %> | |
<tr> <td> <%= file.status %> | </td> <td> <%= file.path %> </td> </tr> | |
<% end %> | |
</table> | |
</description> | |
</item> | |
<% end %> | |
</channel> | |
</rss> | |
EOS | |
if (__FILE__ == $0) | |
OPTIONS = {} | |
OPTIONS[:port] = 3003 | |
OPTIONS[:mnt] = 'svnrss' | |
OPTIONS[:run] = true | |
opts = OptionParser.new do |opts| | |
opts.on("-p", "--port=3003", "Which port do you want the server to listen on.") do |p| | |
OPTIONS[:port] = p.to_i if !p.nil? | |
end | |
opts.on("-m", "--mount-point=svnrss", "http://<your server>/<mount-point>") do |m| | |
OPTIONS[:mnt] = m if !m.nil? | |
end | |
opts.on_tail("-h", "--help", "Show help (this).") do |h| | |
puts opts | |
OPTIONS[:run] = false | |
end | |
end | |
begin | |
opts.parse!(ARGV) | |
rescue Exception => e | |
puts e, "", opts | |
exit | |
end | |
begin | |
if OPTIONS[:run] | |
include WEBrick | |
server = HTTPServer.new(:Port => OPTIONS[:port]) | |
server.mount_proc("/#{OPTIONS[:mnt]}") do |req, res| | |
url = req.query['url'] || "http://svn.codehaus.org/jruby/trunk/" | |
num_revs = req.query['num_revs'].to_i || 100 | |
uid = req.query['uid'] | |
passwd = req.query['password'] | |
repo = RSCM::Subversion.new(url) | |
repo.username = uid if !uid.nil? | |
repo.password = passwd if !passwd.nil? | |
revs = repo.revisions(Time.now - (RSCM::Subversion::TWENTY_FOUR_HOURS * 10)).sort {|r1,r2| | |
r2.time<=>r1.time | |
}.slice(0...num_revs) | |
template = ERB.new(TEMPLATE, 0, "%<>") | |
res.body = template.result(self.send("binding")) | |
res['Content-Type'] = "text/xml" | |
end | |
trap("INT"){ server.shutdown } | |
puts "Server is running here: http://localhost:#{OPTIONS[:port]}/#{OPTIONS[:mnt]}" | |
server.start | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment