gitalytics 1.2.0 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfee4701c631f00b32ae513f27dd761e78bc90c9
4
- data.tar.gz: 18dfec6a19254bd61de7ecb7a65b34b824f610f9
3
+ metadata.gz: 23ec8f357392488c8e0448555e52964f905b723d
4
+ data.tar.gz: f70ec4ccce5ed624a54975f514908bdaaddac4ff
5
5
  SHA512:
6
- metadata.gz: 22ab60c1cc856e08152c8893170c567b82831ff09910c7d4a7e7107cc06576042651ef0001a71a7533da5557b4d31a0ab3d515fe897fb07531e32b62ce1d45b1
7
- data.tar.gz: f24764d467fd4e7df3f06a37804f3185d2e07157241e38764ff70c4e013ccef02c81377c1459998d1f75e1daf3f729d4c560d8395b8e26e8eff50f0a1c24b9b0
6
+ metadata.gz: 7729801e99f39eff2f1beaa305997438b466ac82da113f306340ee1327724aa30b7ca8a969b13dd3004ff9a0a75dda21a5d53e00faf1e70b894d2e12581d0c60
7
+ data.tar.gz: acca7a0f6e4a96a6a85867a1381dad0cf27b3eafff4c4eb88b66ae8ac88854cd0d23a5b391c9431869e6ccedc9628defb7722ffe24c0f85203d65ba8be9047d2
@@ -156,14 +156,14 @@
156
156
  <div class="col-md-4">
157
157
  <div class="dashboard-box">
158
158
  <span class="glyphicon glyphicon-plus"></span><br>
159
- <%= @commits.map{ |c| c.insertions }.inject(0){ |total, current| total + current } %>
159
+ <%= @commits.inject(0) { |total, commit| total + commit.insertions } %>
160
160
  insertions
161
161
  </div>
162
162
  </div>
163
163
  <div class="col-md-4">
164
164
  <div class="dashboard-box">
165
165
  <span class="glyphicon glyphicon-minus"></span><br>
166
- <%= @commits.map{ |c| c.deletions }.inject(0){ |total, current| total + current } %>
166
+ <%= @commits.inject(0) { |total, commit| total + commit.deletions } %>
167
167
  deletions
168
168
  </div>
169
169
  </div>
@@ -0,0 +1,22 @@
1
+ class Commit
2
+
3
+ attr_accessor :hash, :author, :date, :subject, :summary
4
+
5
+ def initialize(hash)
6
+ self.hash = hash
7
+ self.summary = []
8
+ end
9
+
10
+ def insertions
11
+ summary.inject(0) { |total, current| total + current[:insertions] }
12
+ end
13
+
14
+ def deletions
15
+ summary.inject(0) { |total, current| total + current[:deletions] }
16
+ end
17
+
18
+ def files_committed
19
+ summary.map{ |s| s[:filename] }
20
+ end
21
+
22
+ end
@@ -1,16 +1,13 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'date'
4
3
  require 'erb'
5
- require 'digest/md5'
6
-
7
4
  require 'gitlog'
8
5
  require 'user'
9
6
  require 'commit'
10
7
 
11
8
  class Gitalytics
12
9
 
13
- VERSION = '1.2.0'
10
+ VERSION = '1.2.1'
14
11
 
15
12
  def analyze(options)
16
13
  data = GitLog.parse_git_log
@@ -0,0 +1,75 @@
1
+ require 'commit'
2
+ require 'user'
3
+ require 'date'
4
+
5
+ module GitLog
6
+
7
+ module_function
8
+
9
+ def parse_git_log
10
+ users, commits = [], []
11
+
12
+ log = get_log
13
+ blocks = get_blocks(log)
14
+
15
+ blocks.each do |(hash, block_string)|
16
+ commits << parse_block(hash, block_string, users)
17
+ end
18
+
19
+ {users: users, commits: commits}
20
+ end
21
+
22
+ def get_log
23
+ `git log --numstat --pretty='%H %ai %an <%ae> %s'`
24
+ end
25
+
26
+ def get_blocks(log_string)
27
+ commits = log_string.scan(/^([a-f0-9]{40})/).map(&:first)
28
+ blocks = log_string.split(/^[a-f0-9]{40}/).map(&:strip)
29
+ blocks.shift # get rid of first empty string
30
+
31
+ commits.zip(blocks)
32
+ end
33
+
34
+ def parse_block(hash, block_string, users)
35
+ commit = Commit.new(hash)
36
+
37
+ block_string.encode!('UTF-8', 'UTF8-MAC') if defined?(Encoding::UTF8_MAC)
38
+
39
+ regex = /^(?<date>.{25}) (?<name>.*?) \<(?<email>.*?)> (?<subject>.*?)$/
40
+ data = block_string.match(regex)
41
+ commit.subject = data[:subject]
42
+ commit.date = Date.parse(data[:date])
43
+
44
+ get_commit_author(data, commit, users)
45
+ get_commit_summary(block_string, commit)
46
+
47
+ commit
48
+ end
49
+
50
+ def get_commit_summary(block_string, commit)
51
+ block_string.scan(/^(?<insertions>\d+)\s+(?<deletions>\d+)\s+(?<filename>.*)$/).each do |summary|
52
+ commit.summary << {
53
+ insertions: summary[0].to_i,
54
+ deletions: summary[1].to_i,
55
+ filename: summary[2],
56
+ }
57
+ end
58
+ end
59
+
60
+ def get_commit_author(data, commit, users)
61
+ user = get_user(data[:name], data[:email], users)
62
+
63
+ commit.author = user
64
+ user.commits << commit
65
+ end
66
+
67
+ def get_user(name, email, users)
68
+ users.each do |user|
69
+ return user if user.email == email
70
+ end
71
+ users << new_user = User.new(name, email)
72
+ new_user
73
+ end
74
+
75
+ end
@@ -0,0 +1,58 @@
1
+ require 'digest/md5'
2
+
3
+ class User
4
+
5
+ attr_accessor :name, :email, :commits, :colors
6
+
7
+ def initialize(name, email)
8
+ self.name = name
9
+ self.email = email
10
+ self.commits = []
11
+ self.colors = [rand(255), rand(255), rand(255)].join(', ')
12
+ end
13
+
14
+ def gravatar
15
+ Digest::MD5.hexdigest(email)
16
+ end
17
+
18
+ def first_commit
19
+ commits.min_by(&:date)
20
+ end
21
+
22
+ def last_commit
23
+ commits.max_by(&:date)
24
+ end
25
+
26
+ def commits_period
27
+ (last_commit.date - first_commit.date).to_i + 1
28
+ end
29
+
30
+ def working_days
31
+ commits.map(&:date).uniq.count
32
+ end
33
+
34
+ def total_insertions
35
+ commits.map(&:insertions).inject(0) { |total, current| total + current }
36
+ end
37
+
38
+ def total_deletions
39
+ commits.map(&:deletions).inject(0) { |total, current| total + current }
40
+ end
41
+
42
+ def summary
43
+ "#{name} has made #{commits.count} commits between #{commits_period} days. He/she did something useful on #{working_days} of those days."
44
+ end
45
+
46
+ def rgba(opacity = 1)
47
+ "rgba(#{colors}, #{opacity})"
48
+ end
49
+
50
+ def weekday_commits
51
+ days = Array.new(7) {0}
52
+ commits.each do |c|
53
+ days[c.date.wday] += 1
54
+ end
55
+ days
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gonzalo Robaina
@@ -17,9 +17,12 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - bin/gitalytics
20
21
  - lib/gitalytics.rb
22
+ - lib/gitlog.rb
23
+ - lib/user.rb
24
+ - lib/commit.rb
21
25
  - assets/gitalytics.html.erb
22
- - bin/gitalytics
23
26
  homepage: http://rubygems.org/gems/gitalytics
24
27
  licenses:
25
28
  - MIT