Monday, June 22, 2009

About hooks and cute scripts

This one stands as the the real stress buster in terms of cutting down the amount of work not needed to be done by me now that it is in place.

Here's how I reduced the time taken in giving long code walk through to my colleagues handling maintenance of the same system you do development for after you are done with what all you want to release.

Get a pre-commit hook to your source versioning repository to ensure every check-in has a story or defect ID(We use Rally and subversion), but this can work largely for other similar systems as well. Not really written by me but I took an existing Perl based one and modified a bit to suite my needs


#!/usr/bin/perl

# config section
$minchars = 4;
$svnlook = '/usr/bin/svnlook';

#--------------------------------------------
$repos = $ARGV[0];
$txn = $ARGV[1];
$comment = `$svnlook log -t "$txn" "$repos"`;
chomp($comment);

if ( length($comment) == 0 ) {
print STDERR "A comment is required!";
exit(1);
}
elsif ( length($comment) < $minchars ) {
print STDERR "Comment must be at least $minchars characters.";
exit(1);
}
elsif ($comment !~ m/^S\d{4,}.*/ && $comment !~ m/^DE\d{4,}.*/ $comment !~ m/^Tech.*/){
print STDERR "Comment must have Rally Story Id,Defect Id or Tech as prefix."; exit(1);
}
exit(0);


and then you can use this sweet little thing written by one of my developer colleagues to get a complete history of what in the code base changed how many revisions for a story or defect.


#!/usr/bin/env ruby

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}].log", "w")
revision_separator = "------------------------------------------------------------------------"
commit_log = `svn log #{branch_path} --verbose -r {#{start_date}}:{#{end_date}} --incremental`

file.puts "Branch path: #{branch_path}"
file.puts "Start date: #{start_date}"
file.puts "End date: #{end_date}"
file.puts "Search string: #{search_string}"

for revision_log in commit_log.split(revision_separator)
if revision_log.downcase.include? search_string.downcase
file.puts revision_separator
file.puts revision_log
end
end

file.close()


The good part is that while I might be presenting the release features which always takes it's own good time, I do not have to go through long sessions of browsing code and explaining where is what to the other guys as that info is in these change logs which they can use to see it for themselves.

No comments: