7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/bugspots/scanner.rb', line 7
def self.scan(repo, branch = "master", depth = nil, regex = nil)
regex ||= /\b(fix(es|ed)?|close(s|d)?)\b/i
fixes = []
repo = Rugged::Repository.new(repo)
unless repo.branches.each_name(:local).sort.find { |b| b == branch }
raise ArgumentError, "no such branch in the repo: #{branch}"
end
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_TOPO)
walker.push(repo.branches[branch].target)
walker = walker.take(depth) if depth
walker.each do |commit|
if commit.message.scrub =~ regex
files = commit.diff(commit.parents.first).deltas.collect do |d|
d.old_file[:path]
end
fixes << Fix.new(commit.message.scrub.split("\n").first, commit.time, files)
end
end
hotspots = Hash.new(0)
currentTime = Time.now
oldest_fix_date = fixes.last.date
fixes.each do |fix|
fix.files.each do |file|
t = 1 - ((currentTime - fix.date).to_f / (currentTime - oldest_fix_date))
hotspots[file] += 1/(1+Math.exp((-12*t)+12))
end
end
spots = hotspots.sort_by {|k,v| v}.reverse.collect do |spot|
Spot.new(spot.first, sprintf('%.4f', spot.last))
end
return fixes, spots
end
|