gitalytics 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/gitalytics.html.erb +6 -6
- data/lib/gitalytics.rb +77 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1b786805cf13c4a8f17b163afa2af25c980532
|
4
|
+
data.tar.gz: d1d64351ecdc60d220c962826b615ccd446bda4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7ce84f9931831e5121757d9df55b0f6e7eea8412cb855ef2b62c06681d692439b756b011e1188284f12d5a7e049a3866ea3c125f772b45bf1c3ff85df182c9
|
7
|
+
data.tar.gz: 8fe319543970aed157f4003b2eabb4a544367b8123b086dc83e9795820fd98bebe0db642b27a35b51a37c996d78662cf2127bc70f1da525b070b3b58921cca15
|
data/assets/gitalytics.html.erb
CHANGED
@@ -130,13 +130,13 @@
|
|
130
130
|
<div class="col-md-6">
|
131
131
|
<div class="media">
|
132
132
|
<a class="pull-left" href="#">
|
133
|
-
<img class="media-object dp img-circle" src="<%= "http://www.gravatar.com/avatar/#{user
|
133
|
+
<img class="media-object dp img-circle" src="<%= "http://www.gravatar.com/avatar/#{user.gravatar}" %>" style="width: 100px; height:100px; border-color:<%= "##{user.color}" %>">
|
134
134
|
</a>
|
135
135
|
<div class="media-body">
|
136
|
-
<h4 class="media-heading"><%= user
|
136
|
+
<h4 class="media-heading"><%= user.name %><br><small><%= user.email %></small></h4>
|
137
137
|
<hr style="margin:8px auto">
|
138
|
-
<%= "#{user
|
139
|
-
<%= "He did something useful on #{user
|
138
|
+
<%= "#{user.commits.count} commits between #{user.commits_period} days." %>
|
139
|
+
<%= "He did something useful on #{user.working_days} of those days." %>
|
140
140
|
</div>
|
141
141
|
</div>
|
142
142
|
</div>
|
@@ -147,7 +147,7 @@
|
|
147
147
|
|
148
148
|
<div id="footer">
|
149
149
|
<div class="container">
|
150
|
-
<p class="text-muted">Gitalytics by <a href="http://gonzalo.robaina.me">Gonzalo Robaina</a></p>
|
150
|
+
<p class="text-muted">Gitalytics v<%= VERSION %> by <a href="http://gonzalo.robaina.me">Gonzalo Robaina</a></p>
|
151
151
|
</div>
|
152
152
|
</div>
|
153
153
|
|
@@ -159,7 +159,7 @@
|
|
159
159
|
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
160
160
|
<script src="http://cdnjs.cloudflare.com/ajax/libs/Chart.js/0.2.0/Chart.min.js"></script>
|
161
161
|
<script>
|
162
|
-
var data = [<%= @data[:users].map{|d| "{ value: #{d
|
162
|
+
var data = [<%= @data[:users].map{|d| "{ value: #{d.commits.count}, color: '##{d.color}' }" }.join(',') %>];
|
163
163
|
var ctx = document.getElementById("myChart").getContext("2d");
|
164
164
|
var myNewChart = new Chart(ctx).Pie(data);
|
165
165
|
</script>
|
data/lib/gitalytics.rb
CHANGED
@@ -6,16 +6,16 @@ require 'digest/md5'
|
|
6
6
|
|
7
7
|
class Gitalytics
|
8
8
|
|
9
|
-
VERSION = '1.0.
|
9
|
+
VERSION = '1.0.5'
|
10
10
|
|
11
11
|
attr_accessor :data
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@data = {}
|
14
|
+
@data = { commits: [], users: [] }
|
15
15
|
end
|
16
16
|
|
17
17
|
def analyze(options)
|
18
|
-
|
18
|
+
parse_git_log
|
19
19
|
case options[:format]
|
20
20
|
when 'html'
|
21
21
|
output_html_report
|
@@ -25,22 +25,30 @@ class Gitalytics
|
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
|
-
def
|
29
|
-
|
30
|
-
command = "git log --pretty='%cn|%ce|%cd|%s' --reverse"
|
31
|
-
result = `#{command}`
|
28
|
+
def parse_git_log
|
29
|
+
result = `git log --stat`
|
32
30
|
|
33
31
|
result.each_line do |line|
|
34
|
-
|
35
|
-
|
32
|
+
if match = line.match(/^commit ([0-9a-z]*)$/)
|
33
|
+
@data[:commits] << Commit.new(match[1])
|
34
|
+
elsif match = line.match(/^Author: ([\w ]*) <(.*)>$/)
|
35
|
+
user = get_user(match[1], match[2])
|
36
|
+
@data[:commits].last.author = user
|
37
|
+
user.commits << @data[:commits].last
|
38
|
+
elsif match = line.match(/^Date: (.*)$/)
|
39
|
+
@data[:commits].last.date = Date.parse(match[1])
|
40
|
+
elsif match = line.match(/^ (.*)$/)
|
41
|
+
@data[:commits].last.subject = match[1]
|
42
|
+
elsif match = line.match(/^ ([^ ]+)[ ]+\|[ ]+([\d]+) ([\+]*)([-]*)$/)
|
43
|
+
@data[:commits].last.summary << { filename: match[1], changes: match[2], insertions: match[3], deletions: match[4] }
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
|
-
@data[:users] = get_user_data(lines)
|
39
47
|
end
|
40
48
|
|
41
49
|
def output_cli_report
|
42
50
|
@data[:users].each do |user|
|
43
|
-
puts "#{user
|
51
|
+
puts "#{user.name} has made #{user.commits.count} commits between #{user.commits_period} days. He did something useful on #{user.working_days} of those days."
|
44
52
|
end
|
45
53
|
end
|
46
54
|
|
@@ -50,23 +58,64 @@ class Gitalytics
|
|
50
58
|
File.open("gitalytics_result.html", 'w+') { |file| file.write(erb.result(binding)) }
|
51
59
|
end
|
52
60
|
|
53
|
-
def
|
54
|
-
users
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
def get_user(name, email)
|
62
|
+
@data[:users].each do |u|
|
63
|
+
return u if u.email == email
|
64
|
+
end
|
65
|
+
@data[:users] << new_user = User.new(name, email)
|
66
|
+
new_user
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class User
|
72
|
+
|
73
|
+
attr_accessor :name, :email, :commits, :color
|
74
|
+
|
75
|
+
def initialize(name, email)
|
76
|
+
self.name = name
|
77
|
+
self.email = email
|
78
|
+
self.commits = []
|
79
|
+
self.color = "%06x" % (rand * 0xffffff)
|
80
|
+
end
|
81
|
+
|
82
|
+
def gravatar
|
83
|
+
Digest::MD5.hexdigest(email)
|
84
|
+
end
|
85
|
+
|
86
|
+
def first_commit
|
87
|
+
commits.min_by(&:date)
|
88
|
+
end
|
89
|
+
|
90
|
+
def last_commit
|
91
|
+
commits.max_by(&:date)
|
92
|
+
end
|
93
|
+
|
94
|
+
def commits_period
|
95
|
+
(last_commit.date - first_commit.date).to_i + 1
|
96
|
+
end
|
97
|
+
|
98
|
+
def working_days
|
99
|
+
commits.map(&:date).uniq.count
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
class Commit
|
105
|
+
|
106
|
+
attr_accessor :hash, :author, :date, :subject, :summary
|
107
|
+
|
108
|
+
def initialize(hash)
|
109
|
+
self.hash = hash
|
110
|
+
self.summary = []
|
111
|
+
end
|
112
|
+
|
113
|
+
def insertions
|
114
|
+
summary.map{ |s| s[:insertions].length }.inject(0){ |total, current| total + current }
|
115
|
+
end
|
116
|
+
|
117
|
+
def deletions
|
118
|
+
summary.map{ |s| s[:deletions].length }.inject(0){ |total, current| total + current }
|
70
119
|
end
|
71
120
|
|
72
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitalytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Robaina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Get usefull analytics from your git log
|
14
14
|
email: gonzalor@gmail.com
|