gitalytics 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a98f4434c615280c091a34ec1fbc9ff2e7220a73
4
- data.tar.gz: 7828f0c7488f17c081490db141351e2aeb3598da
3
+ metadata.gz: 0d1b786805cf13c4a8f17b163afa2af25c980532
4
+ data.tar.gz: d1d64351ecdc60d220c962826b615ccd446bda4d
5
5
  SHA512:
6
- metadata.gz: a5aac6614367e91de9c5190feb90973903677f4c38e3ab8fa8c8f7d21cf9fa06983ca6ce4aabd83988c6a9f80e92c26edcc5ecc22847801710387db31bce06c7
7
- data.tar.gz: d947ed9069ca67efab58e2c8f207f3860392034e66c95352dfa3d5ab000414b26a882e515451e4890fc3ef93131dea4f0260170b910a93cb5ae74c12b7e5880d
6
+ metadata.gz: 1e7ce84f9931831e5121757d9df55b0f6e7eea8412cb855ef2b62c06681d692439b756b011e1188284f12d5a7e049a3866ea3c125f772b45bf1c3ff85df182c9
7
+ data.tar.gz: 8fe319543970aed157f4003b2eabb4a544367b8123b086dc83e9795820fd98bebe0db642b27a35b51a37c996d78662cf2127bc70f1da525b070b3b58921cca15
@@ -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[:gravatar]}" %>" style="width: 100px; height:100px; border-color:<%= "##{user[:color]}" %>">
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[:name] %><br><small><%= user[:email] %></small></h4>
136
+ <h4 class="media-heading"><%= user.name %><br><small><%= user.email %></small></h4>
137
137
  <hr style="margin:8px auto">
138
- <%= "#{user[:commits].count} commits between #{(user[:last_date] - user[:first_date]).to_i + 1} days." %>
139
- <%= "He did something useful on #{user[:working_days]} of those days." %>
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[:commits].count}, color: '##{d[:color]}' }" }.join(',') %>];
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>
@@ -6,16 +6,16 @@ require 'digest/md5'
6
6
 
7
7
  class Gitalytics
8
8
 
9
- VERSION = '1.0.4'
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
- log_to_hash
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 log_to_hash
29
- lines = []
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
- parts = line.split('|')
35
- lines << { name: parts[0], email: parts[1], date: Date.parse(parts[2]), subject: parts[3]}
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[:name]} has made #{user[:commits].count} commits between #{(user[:last_date] - user[:first_date]).to_i + 1} days. He did something useful on #{user[:working_days]} of those days."
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 get_user_data(lines)
54
- users = {}
55
- lines.each{ |r| users[r[:email]] = r[:name] }
56
- users.map{ |email, name|
57
- commits = lines.select{ |r| r[:email] == email }
58
- dates = commits.map{ |c| c[:date] }
59
- {
60
- name: name,
61
- email: email,
62
- gravatar: Digest::MD5.hexdigest(email),
63
- color: "%06x" % (rand * 0xffffff),
64
- commits: commits,
65
- first_date: dates.min,
66
- last_date: dates.max,
67
- working_days: dates.uniq.count
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
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: 2013-12-27 00:00:00.000000000 Z
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