Permalink
Browse files

Added -r option for arbitrary regex matching of commit messages refs #9.

  • Loading branch information...
1 parent f38f7a2 commit 423631f232e486f0604821fa21fa4b667dcbde5f @msgerbush msgerbush committed Jan 11, 2012
Showing with 11 additions and 10 deletions.
  1. +8 −3 bin/git-bugspots
  2. +3 −7 lib/bugspots/scanner.rb
View
@@ -23,8 +23,13 @@ OptionParser.new do |opts|
end
# Option: Set Bugfix Indicator
- opts.on('-w', '--words ["w1,w2"]', 'bugfix indicator, ie: "fixes,closed"') do |words|
- options[:words] = words
+ opts.on('-w', '--words ["w1,w2"]', 'bugfix indicator word list, ie: "fixes,closed"') do |words|
+ options[:regex] = Regexp.new(words.split(',').join('|'))
+ end
+
+ # Option: Set Bugfix Indicator
+ opts.on('-r', '--regex [regex]', Regexp, 'bugfix indicator regex, ie: "fix(es|ed)?" or "/fixes #(\d+)/i"') do |regex|
+ options[:regex] = regex
end
# Option: Set Timestamp Display
@@ -41,7 +46,7 @@ options[:branch] ||= "master"
puts "Scanning #{ARGV[0]} repo".foreground(:green)
-fixes, spots = Bugspots.scan(ARGV[0], options[:branch], options[:depth], options[:words])
+fixes, spots = Bugspots.scan(ARGV[0], options[:branch], options[:depth], options[:regex])
puts "\tFound #{fixes.size} bugfix commits, with #{spots.size} hotspots:".foreground(:yellow)
puts
@@ -5,22 +5,18 @@ module Bugspots
Fix = Struct.new(:message, :date, :files)
Spot = Struct.new(:file, :score)
- def self.scan(repo, branch = "master", depth = 500, words = nil)
+ def self.scan(repo, branch = "master", depth = 500, regex = nil)
repo = Grit::Repo.new(repo)
unless repo.branches.find { |e| e.name == branch }
raise ArgumentError, "no such branch in the repo: #{branch}"
end
fixes = []
- if words
- message_matchers = /#{words.split(',').join('|')}/
- else
- message_matchers = /fix(es|ed)?|close(s|d)?/i
- end
+ regex ||= /fix(es|ed)?|close(s|d)?/i
tree = repo.tree(branch)
repo.commits(branch, depth).each do |commit|
- if commit.message =~ message_matchers
+ if commit.message =~ regex
files = commit.stats.files.map {|s| s.first}.select{ |s| tree/s }
fixes << Fix.new(commit.short_message, commit.date, files)
end

0 comments on commit 423631f

Please sign in to comment.