git-graph 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ 
2
+ c]�q�H��%nAY��*ď����PZ\�C�y5��c2 ����͛��a��)� �y�x"Y {� �,e2κ�$X�fXWW���K)5m�����Xmw��5��ڠ����Dy</��Z���h�]�^a 72��5�B��+����go�Œ�bd�Qz����7��-Fp׆�/'�z�o�ʝi6}���c��{�/�Ab@�J�"�5��q�O�"|Q�c au=ϳˆ~8�c��4�k �Po5��8xK3���
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - ree
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "bump"
5
+ gem "rake"
6
+ gem "rspec", "~>2"
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "bump/tasks"
3
+
4
+ task :default do
5
+ sh "rspec spec/"
6
+ end
@@ -0,0 +1,51 @@
1
+ Make graphs from your git history
2
+
3
+ Install
4
+ =======
5
+
6
+ gem install git-graph
7
+
8
+ Usage
9
+ =====
10
+
11
+ ```Bash
12
+ # number of lines in the readme as csv
13
+ git-graph --interval day --output csv "cat Readme.md | wc -l"
14
+ 2013-02-01,24
15
+ 2013-01-31,24
16
+ 2013-01-31,22
17
+ ...
18
+ ```
19
+
20
+ ```Bash
21
+ # number of lines in the readme as line-chart (via google charts)
22
+ git-graph --interval year --output chart "cat Gemfile.lock | grep DEPENDENCIES -A 999 | wc -l"
23
+ ```
24
+ ![Chart](http://chart.apis.google.com/chart?chs=600x500&cht=lc&chxt=x,y&chxl=0:|2010-03-10|2013-03-09|1:|0|97&chd=s:Aos9&chdl=value&chtt=git-graph)
25
+
26
+ ```Bash
27
+ # number of gems the project depends on
28
+ git-graph --interval year --output chart "cat Gemfile.lock | grep DEPENDENCIES -A 999 | wc -l"
29
+
30
+ # number of lines of code
31
+ git-graph --interval year --output chart "find . -name '*.rb' | xargs wc -l | tail -1"
32
+
33
+ # application startup time
34
+ git-graph --interval year --bundle --output chart '(time -p bundle exec rails runner) 2>&1 | grep real | tail -1 | cut -d " " -f 2'
35
+ ```
36
+
37
+ If the script fails the previous output is assumed.
38
+
39
+ TODO
40
+ ====
41
+ - interval month -> first of every month ?
42
+ - interval year -> same day on every year (leap-year adjustment)
43
+ - refactor into a class
44
+ - [spark](https://github.com/topfunky/sparklines) chart ?
45
+
46
+ Author
47
+ ======
48
+ [Michael Grosser](http://grosser.it)<br/>
49
+ michael@grosser.it<br/>
50
+ License: MIT<br/>
51
+ [![Build Status](https://travis-ci.org/grosser/git_graph.png)](https://travis-ci.org/grosser/git_graph)
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'git/graph'
5
+ require 'time'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = <<BANNER
10
+ Make graphs from your git history.
11
+
12
+ Usage:
13
+ git-graph --interval day --output csv "cat Readme.md | wc -l"
14
+
15
+ Options:
16
+ BANNER
17
+ opts.on("-s", "--start DATA", "Start date (default: today)") { |date| options[:start] = Time.parse(date) }
18
+ opts.on("-e", "--end DATA", "End date (default: time of first commit)") { |date| options[:end] = Time.parse(date) }
19
+ opts.on("-o", "--output FORMAT", "Output format - csv|chart") { |format| options[:format] = format }
20
+ opts.on("-i", "--interval INTERVAL", "Interval of git history - year|week|day)") { |interval| options[:interval] = interval }
21
+ opts.on("-b", "--bundle", "Bundle before running command") { options[:bundle] = true }
22
+ opts.on("-h", "--help","Show this.") { puts opts; exit }
23
+ opts.on('-v', '--version','Show Version'){ puts Git::Graph::VERSION; exit}
24
+ end.parse!
25
+
26
+ raise "Give me 1 command" if ARGV.size != 1
27
+
28
+ def run(cmd)
29
+ all = ""
30
+ $stderr.puts cmd
31
+ IO.popen(cmd) do |pipe|
32
+ while str = pipe.gets
33
+ all << str
34
+ $stderr.puts str
35
+ end
36
+ end
37
+ [$?.success?, all]
38
+ end
39
+
40
+ def run!(command)
41
+ result = run(command)
42
+ raise "Command failed #{command}" unless result.first
43
+ result
44
+ end
45
+
46
+ def without_bundler(&block)
47
+ if defined?(Bundler)
48
+ Bundler.with_clean_env(&block)
49
+ else
50
+ yield
51
+ end
52
+ end
53
+
54
+ start = (options[:start] || Time.now)
55
+ finish = (options[:end] || Time.at(run!("git log --reverse --format='%at' | head -1").last.to_i))
56
+ current = start
57
+ raise "Backwards" if start < finish
58
+
59
+ data = {}
60
+
61
+ DAY = 24*60*60
62
+ INTERVALS = {
63
+ "day" => DAY,
64
+ "week" => 7 * DAY,
65
+ "year" => 365 * DAY
66
+ }
67
+
68
+ interval = INTERVALS[options[:interval] || "year"]
69
+
70
+ while current > finish
71
+ date = current.strftime("%Y-%m-%d")
72
+ command = [
73
+ "git checkout `git rev-list -n 1 --before='#{date}' master`",
74
+ ("bundle check || bundle" if options[:bundle]),
75
+ ARGV.first
76
+ ].compact
77
+ success, output = without_bundler { run(command.map { |c| "(#{c})" }.join(" && ")) }
78
+ data[date] = if success
79
+ value = output.split("\n").last.strip
80
+ value =~ /^\d+\.\d+$/ ? value.to_f : value.to_i
81
+ else
82
+ data.values.last || 0
83
+ end
84
+ current -= interval
85
+ end
86
+
87
+ case options[:format]
88
+ when nil, "csv"
89
+ puts "Date,value"
90
+ data.map do |date, value|
91
+ puts "#{date},#{value}"
92
+ end
93
+ when "chart"
94
+ require "google_chart"
95
+ title = "git-graph"
96
+ dates = data.keys.reverse
97
+ values = data.values.reverse
98
+ url = GoogleChart::LineChart.new('600x500', title, false) do |line|
99
+ line.data("value", values)
100
+ line.axis :x, :labels => [dates.first, dates.last]
101
+ line.axis :y, :labels => ['0', values.max]
102
+ end.to_url
103
+ puts url
104
+ else
105
+ raise "Format #{options[:format]} unknonw"
106
+ end
107
+
108
+ run("git checkout master")
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDMjCCAhqg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kAgHdswGsJztOnNnBa3F
18
+ y0kCSWmK6D+x/SbfS6r7Ke07MRqziJdB9GuE1+0cIRuFh8EQ+LN6HXCKM5pon/GU
19
+ ycwMXfl0
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ name = "git-graph"
3
+ require "#{name.gsub("-","/")}/version"
4
+
5
+ Gem::Specification.new name, Git::Graph::VERSION do |s|
6
+ s.summary = "Make graphs from your git history"
7
+ s.authors = ["Michael Grosser"]
8
+ s.email = "michael@grosser.it"
9
+ s.homepage = "http://github.com/grosser/#{name}"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.license = "MIT"
12
+ s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
13
+ s.cert_chain = ["gem-public_cert.pem"]
14
+ s.executables = ["git-graph"]
15
+ s.add_runtime_dependency "gchartrb"
16
+ end
@@ -0,0 +1,6 @@
1
+ require "git/graph/version"
2
+
3
+ module Git
4
+ module Graph
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Graph
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,106 @@
1
+ require "spec_helper"
2
+ require "tmpdir"
3
+
4
+ describe Git::Graph do
5
+ it "has a VERSION" do
6
+ Git::Graph::VERSION.should =~ /^[\.\da-z]+$/
7
+ end
8
+
9
+ context "CLI" do
10
+ def run(command, options={})
11
+ result = `#{command}`
12
+ raise "FAILED #{command}\n#{result}" if $?.success? == !!options[:fail]
13
+ result
14
+ end
15
+
16
+ def graph(command)
17
+ run "ruby #{Bundler.root.join("bin/git-graph")} #{command}"
18
+ end
19
+
20
+ before :all do
21
+ run("rm -rf #{Bundler.root.join("tmp/parallel")}")
22
+ run("cd #{Bundler.root.join("tmp")} && git clone git@github.com:grosser/parallel.git 2>&1")
23
+ end
24
+
25
+ around do |example|
26
+ Dir.chdir(Bundler.root.join("tmp/parallel")) do
27
+ run("git co master 2>&1")
28
+ example.call
29
+ end
30
+ end
31
+
32
+ it "shows help" do
33
+ graph("--help").should include("-i, --interval INTERVAL")
34
+ end
35
+
36
+ it "shows version" do
37
+ graph("--version").should include(Git::Graph::VERSION)
38
+ end
39
+
40
+ it "graphs years in csv without any arguments" do
41
+ result = graph("'cat lib/parallel.rb | wc -l' 2>/dev/null")
42
+ result.should include("2012-")
43
+ result.should include("2011-")
44
+ end
45
+
46
+ it "graphs years in csv" do
47
+ result = graph("--start 2013-01-01 'cat lib/parallel.rb | wc -l' 2>/dev/null")
48
+ result.should == <<-EXPECTED.gsub(/^\s+/, "")
49
+ Date,value
50
+ 2013-01-01,331
51
+ 2012-01-02,280
52
+ 2011-01-02,258
53
+ 2010-01-02,116
54
+ EXPECTED
55
+ end
56
+
57
+ it "graphs weeks in csv" do
58
+ result = graph("--start 2013-01-01 --end 2012-10-01 --interval week 'cat lib/parallel.rb | wc -l' 2>/dev/null")
59
+ result.should == <<-EXPECTED.gsub(/^\s+/, "")
60
+ Date,value
61
+ 2013-01-01,331
62
+ 2012-12-25,331
63
+ 2012-12-18,331
64
+ 2012-12-11,310
65
+ 2012-12-04,310
66
+ 2012-11-27,310
67
+ 2012-11-20,301
68
+ 2012-11-13,296
69
+ 2012-11-06,296
70
+ 2012-10-30,296
71
+ 2012-10-23,296
72
+ 2012-10-16,296
73
+ 2012-10-09,296
74
+ 2012-10-02,289
75
+ EXPECTED
76
+ end
77
+
78
+ it "fills in missing values with the last value" do
79
+ # this file is not present pre 2011 -> error
80
+ result = graph("--start 2013-01-01 'wc -l lib/parallel/version.rb' 2>/dev/null")
81
+ result.should == <<-EXPECTED.gsub(/^\s+/, "")
82
+ Date,value
83
+ 2013-01-01,3
84
+ 2012-01-02,3
85
+ 2011-01-02,3
86
+ 2010-01-02,3
87
+ EXPECTED
88
+ end
89
+
90
+ it "generates a chart" do
91
+ result = graph("--start 2013-01-01 --output chart 'cat lib/parallel.rb | wc -l' 2>/dev/null")
92
+ result.should include("http://chart.apis.google.com/chart?")
93
+ result.should include("")
94
+ end
95
+
96
+ it "returns to original commit after run" do
97
+ graph("--start 2013-01-01 'cat lib/parallel.rb | wc -l' 2>/dev/null")
98
+ run("git branch | grep '*'").should == "* master\n"
99
+ end
100
+
101
+ it "can bundle" do
102
+ result = graph(%Q{--bundle --start 2013-01-01 '(time -p bundle exec ruby -e "sleep 0.1") 2>&1 | grep real | cut -d " " -f 2' 2>&1})
103
+ result.should =~ /2013-01-01,\d\.\d+.*2012-01-02,\d\.\d+.*2011-01-02,\d\.\d+.*2010-01-02,\d\.\d+/m
104
+ end
105
+ end
106
+ end
@@ -0,0 +1 @@
1
+ require "git/graph"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Grosser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURNakNDQWhxZ0F3SUJB
14
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJBd0RnWURWUVFEREFkdGFX
15
+ Tm8KWVdWc01SY3dGUVlLQ1pJbWlaUHlMR1FCR1JZSFozSnZjM05sY2pFU01C
16
+ QUdDZ21TSm9tVDhpeGtBUmtXQW1sMApNQjRYRFRFek1ESXdNekU0TVRNeE1W
17
+ b1hEVEUwTURJd016RTRNVE14TVZvd1B6RVFNQTRHQTFVRUF3d0hiV2xqCmFH
18
+ RmxiREVYTUJVR0NnbVNKb21UOGl4a0FSa1dCMmR5YjNOelpYSXhFakFRQmdv
19
+ SmtpYUprL0lzWkFFWkZnSnAKZERDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFB
20
+ RGdnRVBBRENDQVFvQ2dnRUJBTW9yWG8vaGdiVXE5NytrSUk5SApNc1FjTGRD
21
+ Lzd3UTF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emlKZEI5R3VFMSswY0lSdUZoOEVRK0xONkhYQ0tN
38
+ NXBvbi9HVQp5Y3dNWGZsMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
+ date: 2013-03-10 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: gchartrb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description:
58
+ email: michael@grosser.it
59
+ executables:
60
+ - git-graph
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .travis.yml
65
+ - Gemfile
66
+ - Rakefile
67
+ - Readme.md
68
+ - bin/git-graph
69
+ - gem-public_cert.pem
70
+ - git-graph.gemspec
71
+ - lib/git/graph.rb
72
+ - lib/git/graph/version.rb
73
+ - spec/git/graph_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/grosser/git-graph
76
+ licenses:
77
+ - MIT
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 3863793032351926901
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: 3863793032351926901
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Make graphs from your git history
106
+ test_files: []
@@ -0,0 +1,2 @@
1
+ ����7 ���0�.����c ��jXT���C�Vv���$��@b���Rb��~���'?�4�wԿ�>K�?�;3\}�EF��q�/a{wI�C�)̔�L�A﹩5!��=�m����s��^B��A����{�����C[��PTA�����7룣�6���aR9G��sV,3��j�N4���ܭ�m��E-T���(!�k��4���-���>7ޜ��.�� �z�ױ��.��
2
+ �����J�A)����F{��Q