hans-gitchart 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE +21 -0
  2. data/Rakefile +18 -0
  3. data/bin/git-chart +12 -0
  4. data/gitchart.gemspec +27 -0
  5. data/lib/gitchart.rb +167 -0
  6. metadata +75 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 Hans Engel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ =begin
2
+ Copyright (c) 2008 Hans Engel
3
+ See the file LICENSE for licensing details.
4
+ =end
5
+
6
+ require 'rubygems'
7
+ Gem::manage_gems
8
+ require 'rake/gempackagetask'
9
+
10
+ spec = eval(File.read('gitchart.gemspec'))
11
+
12
+ Rake::GemPackageTask.new(spec) do |pkg|
13
+ pkg.need_tar = true
14
+ end
15
+
16
+ task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
17
+ puts 'generated latest version'
18
+ end
data/bin/git-chart ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+ Copyright (c) 2008 Hans Engel
5
+ See the file LICENSE for licensing details.
6
+ =end
7
+
8
+ begin; require 'rubygems'; rescue LoadError; end
9
+ require 'gitchart'
10
+
11
+ gc = GitChart.new
12
+ gc.run
data/gitchart.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ =begin
2
+ Copyright (c) 2008 Hans Engel
3
+ See the file LICENSE for licensing details.
4
+ =end
5
+
6
+ Gem::Specification.new do |s|
7
+ s.platform = Gem::Platform::RUBY
8
+ s.name = 'gitchart'
9
+ s.version = '1.0'
10
+ s.date = '2008-08-23'
11
+ s.homepage = 'http://github.com/hans/gitchart'
12
+ s.author = 'Hans Engel'
13
+ s.email = 'spam.me@engel.uk.to'
14
+ s.summary = 'Generate cool stats about Git repositories'
15
+ s.files = [
16
+ 'LICENSE',
17
+ 'Rakefile',
18
+ 'gitchart.gemspec',
19
+ 'lib/gitchart.rb',
20
+ 'lib/platform.rb',
21
+ 'bin/git-chart']
22
+ s.bindir = 'bin'
23
+ s.executables = ['git-chart']
24
+ s.require_paths = ['lib']
25
+ s.add_dependency('gchartrb', '>= 0.8')
26
+ s.add_dependency('schacon-grit', '>= 0.9.3')
27
+ end
data/lib/gitchart.rb ADDED
@@ -0,0 +1,167 @@
1
+ =begin
2
+ Copyright (c) 2008 Hans Engel
3
+ See the file LICENSE for licensing details.
4
+ =end
5
+
6
+ require 'ftools'
7
+ require 'tempfile'
8
+
9
+ require 'gitchart'
10
+ require 'platform'
11
+ require 'google_chart'
12
+ include GoogleChart
13
+ require 'grit'
14
+ include Grit
15
+
16
+ class GitChart
17
+ def initialize(size = '1000x300', threed = true, repo = '.', branch = 'master')
18
+ begin
19
+ @repo = Repo.new(repo)
20
+ rescue
21
+ raise "Could not initialize Grit instance."
22
+ end
23
+ @size = size
24
+ @threed = threed
25
+ @branch = branch
26
+ @files = 0
27
+ if repo == '.'
28
+ rpath = Dir.getwd
29
+ else
30
+ rpath = repo
31
+ end
32
+ @html = <<EOF
33
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
34
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
35
+ <html xmlns="http://www.w3.org/1999/xhtml">
36
+ <head profile="http://purl.org/uF/2008/03">
37
+ <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
38
+ <style type="text/css">
39
+ * { margin: 0; padding: 0; }
40
+ body { width: 1000px; margin: 50px auto; overflow: auto; text-align: center; font-size: 13px; }
41
+ h1 { font-weight: normal; font-size: 20px; }
42
+ table { border: none; margin: 20px auto; width: 500px; }
43
+ tr { border: none; }
44
+ td { border: none; padding: 7px; }
45
+ td.key { background-color: #c7e4e5; width: 145px; font-weight: bold; font-size: 11px; }
46
+ </style>
47
+ <title>gitchart output</title>
48
+ </head>
49
+ <body>
50
+ <h1>Git Repository Stats</h1>
51
+ <p>These stats were generated by <a href="http://github.com/hans/git-chart"><code>git-chart</code></a>.
52
+ <table cellpadding="0" cellspacing="0">
53
+ <tr>
54
+ <td class="key">repository location:</td>
55
+ <td>#{rpath}</td>
56
+ </tr>
57
+ <tr>
58
+ <td class="key">generated on:</td>
59
+ <td>#{Time.now.to_s}</td>
60
+ </tr>
61
+ </table>
62
+
63
+ EOF
64
+ end
65
+
66
+ def run
67
+ @commits = @repo.commits @branch, 100
68
+ chart_authors
69
+ chart_commits
70
+ chart_extensions
71
+ chart_awesomeness
72
+ output
73
+ end
74
+
75
+ def chart_authors
76
+ authors = {}
77
+ @commits.each do |c|
78
+ if authors[c.author.to_s]
79
+ authors[c.author.to_s] += 1
80
+ else
81
+ authors[c.author.to_s] = 1
82
+ end
83
+ end
84
+ PieChart.new(@size, 'Repository Authors', @threed) do |pc|
85
+ authors.each do |a, num|
86
+ pc.data a, num
87
+ end
88
+ @html += "<img src='#{pc.to_url}' alt='Repository Authors' /><br/>"
89
+ end
90
+ end
91
+
92
+ def chart_commits
93
+ weeks = Array.new 53, 0
94
+ @commits.each do |c|
95
+ time = Time.parse c.committed_date.to_s
96
+ week = time.strftime '%U'
97
+ weeks[week.to_i] ||= 0
98
+ weeks[week.to_i] += 1
99
+ end
100
+ BarChart.new(@size, 'Commit Frequency', :vertical, @threed) do |bc|
101
+ bc.data '', weeks
102
+ bc.axis :y, { :range => [0, weeks.max] }
103
+ @html += "<img src='#{bc.to_url}' alt='Commit Frequency' /><br/>"
104
+ end
105
+ end
106
+
107
+ def chart_extensions
108
+ @extensions = {}
109
+ @tree = @commits.first.tree
110
+ extensions_add_tree @tree
111
+ PieChart.new(@size, 'Popular Extensions', @threed) do |pc|
112
+ @extensions.each do |ext, num|
113
+ pc.data ext, num
114
+ end
115
+ @html += "<img src='#{pc.to_url}' alt='Popular Extensions' /><br/>"
116
+ end
117
+ end
118
+ def extensions_add_tree(tree)
119
+ tree.contents.each do |el|
120
+ if Blob === el
121
+ extensions_add_blob el
122
+ elsif Tree === el
123
+ extensions_add_tree el
124
+ end
125
+ end
126
+ end
127
+ def extensions_add_blob(el)
128
+ ext = File.extname el.name
129
+ if ext == ''
130
+ @extensions['Other'] += 1 rescue @extensions['Other'] = 1
131
+ else
132
+ @extensions[ext] += 1 rescue @extensions[ext] = 1
133
+ end
134
+ @files += 1
135
+ end
136
+
137
+ def chart_awesomeness
138
+ @extensions['.rb'] ||= 0.1
139
+ awesomeness = @files / @extensions['.rb']
140
+ awesomeness = ( awesomeness * 100 ).round / 100.0
141
+ awesomeness = 0.1 if @extensions['.rb'] == 0.1
142
+ url = "http://chart.apis.google.com/chart?cht=gom&chtt=Repository+Awesomeness&chs=#{@size}&chl=#{awesomeness}%25&chd=t:#{awesomeness}"
143
+ @html += "<img src='#{url}' alt='Repository Awesomeness' /><br/><br/>"
144
+ end
145
+
146
+ def output
147
+ @html += <<EOF
148
+ </body>
149
+ </html>
150
+ EOF
151
+ t = Tempfile.new 'gitchart-' + Time.now.to_i.to_s
152
+ t.print @html
153
+ t.flush
154
+ f = t.path + '.html'
155
+ File.move t.path, f
156
+ case Platform::OS
157
+ when :unix:
158
+ if Platform::IMPL == :macosx
159
+ `open #{f}`
160
+ else
161
+ `xdg-open #{f}`
162
+ end
163
+ when :win32:
164
+ `start #{f}`
165
+ end
166
+ end
167
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hans-gitchart
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Hans Engel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-23 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gchartrb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0.8"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: schacon-grit
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.3
32
+ version:
33
+ description:
34
+ email: spam.me@engel.uk.to
35
+ executables:
36
+ - git-chart
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - LICENSE
43
+ - Rakefile
44
+ - gitchart.gemspec
45
+ - lib/gitchart.rb
46
+ - lib/platform.rb
47
+ - bin/git-chart
48
+ has_rdoc: false
49
+ homepage: http://github.com/hans/gitchart
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.2.0
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Generate cool stats about Git repositories
74
+ test_files: []
75
+