Wednesday, March 2, 2011

yet another svn change log tool

this one helps organize revisions to path entries based on a commit message. Will work only if you have enforced a pre-commit hook that ensures every commit has a message which starts with some sort of an ID for the change request/feature/defect fix for which the commit is being made.

It's very raw (I am still far away from being a good ruby programmer) but works well for now....

#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
branch_path = ARGV[0]
start_date = ARGV[1]
end_date = ARGV[2]
search_string = ARGV[3]

file = File.new("svn_logs_#{start_date}-#{end_date}_[#{search_string}].xml", "w")
file.puts("")
file.puts("")
file.puts(`svn log #{branch_path} --verbose -r {#{start_date}}:{#{end_date}} --incremental --xml`)
file.puts("")

document = Nokogiri::XML(File.new("svn_logs_#{start_date}-#{end_date}_[#{search_string}].xml"))
path_entries = document.xpath("//path")
entries_array = []
path_entries.each do |entry|
    entries_array << entry.content
end
uniq_entries = entries_array.uniq

changeFile = File.new("change_log_#{start_date}-#{end_date}_[#{search_string}].txt", "w")
revision_separator = "------------------------------------------------------------------------"
changeFile.puts "Branch path: #{branch_path}"
changeFile.puts "Start date: #{start_date}"
changeFile.puts "End date: #{end_date}"
changeFile.puts "Search string: #{search_string}"

for uniq in uniq_entries
    published = false
    logentries = document.xpath("//path[text()='#{uniq}']/../..")
    logentries.each do |logentry|
        if logentry.xpath(".//msg/text()").to_s.downcase.include? search_string.downcase
            puts(logentry.xpath(".//msg/text()").to_s)
             if published == false
                changeFile.puts(revision_separator)
                changeFile.puts "Path: #{uniq}"
                changeFile.puts "Revisions Changed:"
             end
                published = true
                changeFile.puts("\t #{logentry.attr("revision")}")
        end
    end
end
changeFile.close()
file.close()

and here's the output
Branch path: svn://my.svn.com/repo/trunk
Start date: 2011-02-09
End date: 2011-03-02
Search string: S6556
------------------------------------------------------------------------
Path: /trunk/cminput/data/release/1103-release.xml
Revisions Changed:
         57979
         58023
         58049
         58091
         58095
         58225
         58226
         58232
------------------------------------------------------------------------
Path: /trunk/gpd/xml/templates/product-color.xml
Revisions Changed:
         57979
         58006
         58020
         58055
         58087
         58091
------------------------------------------------------------------------
Path: /trunk/gpd/src/main/java/com/someapp/gpd/policy/productcolor/ProductColorPolicy.java
Revisions Changed:
         57979
         58020
         58023
         58055
         58087
         58091

No comments: