Skip to content

Commit

Permalink
Added -r option for arbitrary regex matching of commit messages refs #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
msgerbush committed Jan 11, 2012
1 parent f38f7a2 commit 423631f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 8 additions & 3 deletions bin/git-bugspots
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 3 additions & 7 deletions lib/bugspots/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 423631f

Please sign in to comment.