jeremyf-rails-stat-bucket 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +6 -0
- data/Rakefile +59 -0
- data/TODO +4 -0
- data/bin/rails-stat-bucket +46 -0
- data/lib/rails-stat-bucket.rb +74 -0
- data/test/rails-stat-bucket_test.rb +7 -0
- data/test/test_helper.rb +3 -0
- metadata +71 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jeremy Friesen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
h1. rails-stat-bucket
|
2
|
+
|
3
|
+
A simple gem that will traverse your Git history and report the rails stats for each day in the projects life.
|
4
|
+
|
5
|
+
|
6
|
+
!http://chart.apis.google.com/chart?cht=lc&chs=525x525&chds=0,2385&chd=t:22,771,799,948,877,1077,1100,1100,1470,1488,1605,1709,1815,1857,2051,2113,2241,2247,2279,2278,2278,2320,2385|21,648,745,901,647,881,895,895,1093,1146,1320,1426,1640,1780,1880,1984,1988,1988,2009,2009,2009,2088,2161&chxt=y&chdl=LOC|TLOC&chco=FF0000,0000FF&chxl=0:|0|500|1000|1500|2000|2500(Example Output)!:http://chart.apis.google.com/chart?cht=lc&chs=525x525&chds=0,2385&chd=t:22,771,799,948,877,1077,1100,1100,1470,1488,1605,1709,1815,1857,2051,2113,2241,2247,2279,2278,2278,2320,2385|21,648,745,901,647,881,895,895,1093,1146,1320,1426,1640,1780,1880,1984,1988,1988,2009,2009,2009,2088,2161&chxt=y&chdl=LOC|TLOC&chco=FF0000,0000FF&chxl=0:|0|500|1000|1500|2000|2500
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
require "rake/testtask"
|
6
|
+
|
7
|
+
GEM = "rails-stat-bucket"
|
8
|
+
GEM_VERSION = "0.4.0"
|
9
|
+
AUTHOR = "Jeremy Friesen"
|
10
|
+
EMAIL = "reclusive.geek@gmail.com"
|
11
|
+
HOMEPAGE = "http://github.com/jeremyf/rails-stat-bucket"
|
12
|
+
SUMMARY = "A simple gem that will traverse your Git history and report the rails stats for each day in the projects life."
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = GEM
|
16
|
+
s.version = GEM_VERSION
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.bindir = 'bin'
|
20
|
+
s.executables = GEM
|
21
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
|
22
|
+
s.summary = SUMMARY
|
23
|
+
s.description = s.summary
|
24
|
+
s.author = AUTHOR
|
25
|
+
s.email = EMAIL
|
26
|
+
s.homepage = HOMEPAGE
|
27
|
+
|
28
|
+
s.add_dependency("main", ">=2.8.3")
|
29
|
+
|
30
|
+
s.require_path = 'lib'
|
31
|
+
s.autorequire = GEM
|
32
|
+
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,test,bin}/**/*")
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
desc "Run tests"
|
38
|
+
Rake::TestTask.new do |test|
|
39
|
+
test.libs << "test"
|
40
|
+
test.test_files = [ "test/**/*_test.rb" ]
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
46
|
+
pkg.gem_spec = spec
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "install the gem locally"
|
50
|
+
task :install => [:package] do
|
51
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "create a gemspec file"
|
55
|
+
task :make_spec do
|
56
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
57
|
+
file.puts spec.to_ruby
|
58
|
+
end
|
59
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'main'
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../lib/rails-stat-bucket'
|
4
|
+
|
5
|
+
graph_lambda = lambda {
|
6
|
+
description 'Generate a graph of the stats using Googles Graph API'
|
7
|
+
}
|
8
|
+
stat_bucket_file_lambda = lambda {
|
9
|
+
default 'rails-stat-bucket.yml'
|
10
|
+
arity 1
|
11
|
+
description 'Name of the generated rails-stat-bucket'
|
12
|
+
}
|
13
|
+
Main do
|
14
|
+
description 'A simple script that traverses the Git history of a Rails project and generates the stats'
|
15
|
+
|
16
|
+
def run
|
17
|
+
help!
|
18
|
+
end
|
19
|
+
mode 'generate' do
|
20
|
+
description 'Read the git history and collect the stats, writing them to the output file.'
|
21
|
+
|
22
|
+
def run
|
23
|
+
RailsStatBucket.generate(params['directory'].value, params['output_file'].value, { :verbose => params['all'].given?, :graph => params['graph'].given?})
|
24
|
+
end
|
25
|
+
|
26
|
+
argument('directory') {
|
27
|
+
default './'
|
28
|
+
arity 1
|
29
|
+
description 'The directory that contains the Git repository'
|
30
|
+
}
|
31
|
+
option('all', 'a') {
|
32
|
+
description 'Generate the stats for each commit; This will take some time.'
|
33
|
+
}
|
34
|
+
option('graph', 'g', &graph_lambda)
|
35
|
+
option('output_file', 'o', &stat_bucket_file_lambda)
|
36
|
+
end
|
37
|
+
|
38
|
+
mode 'graph' do
|
39
|
+
description 'Graph the stats from the filename'
|
40
|
+
|
41
|
+
def run
|
42
|
+
RailsStatBucket.graph(params['filename'].value)
|
43
|
+
end
|
44
|
+
argument('filename', &stat_bucket_file_lambda)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module RailsStatBucket
|
3
|
+
def self.generate(input_directory, output_filename, options = {})
|
4
|
+
git = `which git`.strip
|
5
|
+
rake = `which rake`.strip
|
6
|
+
if system("cd #{input_directory} && #{git} status | grep 'nothing to commit' > /dev/null")
|
7
|
+
begin
|
8
|
+
puts 'Nothing to commit, proceeding with stats check.'
|
9
|
+
|
10
|
+
previous_date = nil
|
11
|
+
@collector = []
|
12
|
+
|
13
|
+
%x{cd #{input_directory} && #{git} log --date=short | grep 'Date:' -B 2}.split('--').each do |log_entry|
|
14
|
+
if matched_data = log_entry.match(/^Date: +(\d{4}-\d{2}-\d{2})/)
|
15
|
+
current_date = matched_data[1]
|
16
|
+
if options[:verbose] || previous_date != current_date
|
17
|
+
if match_commit_entry = log_entry.match(/^commit (\w+)/)
|
18
|
+
commit_id = match_commit_entry[1]
|
19
|
+
stats = %x(cd #{input_directory} && #{git} checkout #{commit_id} && #{rake} stats)
|
20
|
+
if match_stats = stats.match(/^ +Code LOC: ?(\d+) +Test LOC: ?(\d+)/)
|
21
|
+
@collector << {:date => current_date, :lines_of_code => match_stats[1].to_i, :lines_of_test_code => match_stats[2].to_i }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
previous_date = current_date
|
26
|
+
end
|
27
|
+
end
|
28
|
+
File.open(output_filename, 'w+') do |file|
|
29
|
+
YAML.dump(@collector, file)
|
30
|
+
end
|
31
|
+
ensure
|
32
|
+
`cd #{input_directory} && #{git} checkout master`
|
33
|
+
end
|
34
|
+
|
35
|
+
if options[:graph]
|
36
|
+
graph(output_filename)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
puts "Unable to proceed with stat check. Uncommited changes found in #{input_directory}"
|
40
|
+
exit!(-1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.graph(input_file)
|
45
|
+
input = YAML.load_file(input_file)
|
46
|
+
lines_of_test_code = []
|
47
|
+
lines_of_code = []
|
48
|
+
input.each {|input|
|
49
|
+
lines_of_test_code << input[:lines_of_test_code]
|
50
|
+
lines_of_code << input[:lines_of_code]
|
51
|
+
}
|
52
|
+
upper_limit = [lines_of_test_code.max, lines_of_code.max].max
|
53
|
+
|
54
|
+
url_query_elements = []
|
55
|
+
url_query_elements << "cht=lc" # Line chart
|
56
|
+
url_query_elements << "chs=525x525" # chart size
|
57
|
+
url_query_elements << "chds=0,#{upper_limit}" # chart data scale
|
58
|
+
url_query_elements << "chd=t:#{lines_of_code.reverse.join(',')}\\\|#{lines_of_test_code.reverse.join(',')}" #chart data
|
59
|
+
url_query_elements << "chxt=y" # chart axis
|
60
|
+
url_query_elements << "chdl=LOC\\\|TLOC"
|
61
|
+
url_query_elements << "chco=FF0000,0000FF"
|
62
|
+
|
63
|
+
labels = [0]
|
64
|
+
i = 0
|
65
|
+
while i < upper_limit do
|
66
|
+
i += 500
|
67
|
+
labels << i
|
68
|
+
end
|
69
|
+
url_query_elements << "chxl=0:\\\|#{labels.join("\\\|")}" # chart axis
|
70
|
+
url = "http://chart.apis.google.com/chart?#{url_query_elements.join("\\\&")}"
|
71
|
+
puts url
|
72
|
+
`open #{url}`
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jeremyf-rails-stat-bucket
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Friesen
|
8
|
+
autorequire: rails-stat-bucket
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-07 00:00:00 -07:00
|
13
|
+
default_executable: rails-stat-bucket
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: main
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.8.3
|
24
|
+
version:
|
25
|
+
description: A simple gem that will traverse your Git history and report the rails stats for each day in the projects life.
|
26
|
+
email: reclusive.geek@gmail.com
|
27
|
+
executables:
|
28
|
+
- rails-stat-bucket
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.textile
|
33
|
+
- LICENSE
|
34
|
+
- TODO
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.textile
|
38
|
+
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- lib/rails-stat-bucket.rb
|
41
|
+
- test/rails-stat-bucket_test.rb
|
42
|
+
- test/test_helper.rb
|
43
|
+
- bin/rails-stat-bucket
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/jeremyf/rails-stat-bucket
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: A simple gem that will traverse your Git history and report the rails stats for each day in the projects life.
|
70
|
+
test_files: []
|
71
|
+
|