Skip to content
Browse files

import bugspots

  • Loading branch information...
0 parents commit 980fba9513b4078560b4a68042654b29de053b17 @igrigorik committed Dec 14, 2011
Showing with 91 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +1 −0 Rakefile
  4. +16 −0 bin/bugspots
  5. +27 −0 bugspots.gemspec
  6. +2 −0 lib/bugspots.rb
  7. +34 −0 lib/bugspots/scanner.rb
  8. +3 −0 lib/bugspots/version.rb
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in bugspots.gemspec
+gemspec
1 Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
16 bin/bugspots
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
+
+require 'bugspots'
+require 'optparse'
+
+ARGV << '--help' if ARGV.empty?
+
+options = {}
+OptionParser.new do |opts|
+ opts.banner = "Usage: bugspots /path/to/git/repo"
+end.parse!
+
+Bugspots.scan(ARGV[0])
27 bugspots.gemspec
@@ -0,0 +1,27 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "bugspots/version"
+
+Gem::Specification.new do |s|
+ s.name = "bugspots"
+ s.version = Bugspots::VERSION
+ s.authors = ["Ilya Grigorik"]
+ s.email = ["ilya@igvita.com"]
+ s.homepage = "https://github.com/igrigorik/bugspots"
+ s.summary = "Implementation of simple bug prediction hotspot heuristic"
+ s.description = s.summary
+
+ s.rubyforge_project = "bugspots"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency "grit"
+ s.add_dependency "rainbow"
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
2 lib/bugspots.rb
@@ -0,0 +1,2 @@
+require "bugspots/version"
+require "bugspots/scanner"
34 lib/bugspots/scanner.rb
@@ -0,0 +1,34 @@
+require 'rainbow'
+require 'grit'
+
+module Bugspots
+ Fix = Struct.new(:message, :date, :files)
+
+ def self.scan(repo)
+ puts "Scanning #{repo} repo".foreground(:green)
+ repo = Grit::Repo.new(repo)
+ fixes = []
+
+ repo.commits('master', 500).each do |commit|
+ if commit.message =~ /fix(es|ed)|close(s|d)/
+ files = commit.stats.files.map {|s| s.first}
+ fixes << Fix.new(commit.message, commit.date, files)
+ end
+ end
+
+ hotspots = Hash.new(0)
+ fixes.each do |fix|
+ fix.files.each do |file|
+ t = 1 - ((Time.now - fix.date).to_f / (Time.now - fixes.last.date))
+ hotspots[file] += (1/(1+Math.exp(-12*t)+12))
+ end
+ end
+
+ puts "\tFound #{fixes.size} bugfix commits, with #{hotspots.size} hotspots:".foreground(:yellow)
+ puts
+
+ hotspots.sort_by {|k,v| v}.reverse.each do |spot|
+ puts "\t#{spot.last.round(2)}".foreground(:red) + " - #{spot.first}".foreground(:yellow)
+ end
+ end
+end
3 lib/bugspots/version.rb
@@ -0,0 +1,3 @@
+module Bugspots
+ VERSION = "0.0.1"
+end

0 comments on commit 980fba9

Please sign in to comment.
Something went wrong with that request. Please try again.