Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branch option. #7

Merged
merged 1 commit into from Dec 16, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bin/bugspots
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ options = {}
OptionParser.new do |opts|
opts.banner = "Usage: bugspots /path/to/git/repo"

# Option: Set Branch
opts.on('-b', '--branch [name]', 'branch to crawl') do |b|
options[:branch] = b.to_s
end

# Option: Set Depth
opts.on('-d', '--depth [depth]', 'depth of log crawl (integer)') do |d|
options[:depth] = d.to_i
Expand All @@ -28,12 +33,15 @@ OptionParser.new do |opts|
end
end.parse!

# Set a reasonable default of depth
# Set a reasonable default of depth
options[:depth] ||= 500

# Set master as the default branch
options[:branch] ||= "master"

puts "Scanning #{ARGV[0]} repo".foreground(:green)

fixes, spots = Bugspots.scan(ARGV[0], options[:depth], options[:words])
fixes, spots = Bugspots.scan(ARGV[0], options[:branch], options[:depth], options[:words])

puts "\tFound #{fixes.size} bugfix commits, with #{spots.size} hotspots:".foreground(:yellow)
puts
Expand Down
4 changes: 2 additions & 2 deletions lib/bugspots/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Bugspots
Fix = Struct.new(:message, :date, :files)
Spot = Struct.new(:file, :score)

def self.scan(repo, depth = 500, words = nil)
def self.scan(repo, branch = "master", depth = 500, words = nil)
repo = Grit::Repo.new(repo)
fixes = []

Expand All @@ -15,7 +15,7 @@ def self.scan(repo, depth = 500, words = nil)
message_matchers = /fix(es|ed)|close(s|d)/
end

repo.commits('master', depth).each do |commit|
repo.commits(branch, depth).each do |commit|
if commit.message =~ message_matchers
files = commit.stats.files.map {|s| s.first}
fixes << Fix.new(commit.short_message, commit.date, files)
Expand Down