Created
August 31, 2009 11:27
-
-
Save jasonmadigan/178405 to your computer and use it in GitHub Desktop.
Find last subversion commit by a given user
This file contains hidden or 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 | |
# Give me a username and how many days back you want me to search, | |
# and I'll tell you when this user last made a commit to a given repository. | |
# Deal? | |
# Usage: ./last_commit.rb -b 10 -u <SVN Username> -r http://svn/trunk | |
require 'rubygems' | |
require 'activesupport' | |
require 'optparse' | |
require 'hpricot' # _why :) | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: last_commit.rb [options]" | |
opts.on("-b", "--back [DAYS]", "How many days to search back") do |days| | |
options[:days] = days.to_i | |
end | |
opts.on("-u", "--user [USER]", "User to search for") do |user| | |
options[:user] = user | |
end | |
opts.on("-r", "--r [URL]", "URL for repo to search") do |url| | |
options[:url] = url | |
end | |
end.parse! | |
tr = '%Y-%m-%d %H:%M:%S +0000' | |
start_date = Time.now.strftime(tr) | |
end_date = (Time.now - options[:days].days).strftime(tr) | |
doc = `svn log #{options[:url]} --xml -r "{#{start_date}}:{#{end_date}}"` | |
log = Hpricot(doc) | |
authors = log.search('//author') | |
authors.each_with_index do |a, i| | |
if a.inner_html == options[:user] | |
committed_at = a.parent.search('//date').inner_html.to_time | |
message = a.parent.search('//msg').inner_html | |
revision = a.parent["revision"] | |
puts "\nLast commit by #{options[:user]}: #{committed_at}" | |
puts "#{revision}: #{message}\n\n" | |
break | |
end | |
if i == authors.length-1 | |
puts "Couldn't find a last commit for #{options[:user]} in the last #{options[:days]} days" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment