git-commits-analyzer 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git-commits-analyzer.rb +78 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d25118787113278e054fb55fde763528447016
|
4
|
+
data.tar.gz: c318ffc90587c4409fbbc0adcf04877dda5beabf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 547d7c8c36f0a7edc6ce5cd9acd85616e5024b51626506302294ee4d3c53e68aa9cad248fd2cdbe37854484d1e52c5409ed731bf7aaa2e690c9c2b3cc4a9b472
|
7
|
+
data.tar.gz: 1ed0646e196acf3bf0a52e21ab2cc947b79f4fd0e9e90fa3e9b52ea029e1e474563a37cf1de1167c94b7092ea8daf1d581d0ba5e2f1f6008df61a446b0340e9b
|
data/lib/git-commits-analyzer.rb
CHANGED
@@ -29,6 +29,9 @@ class GitCommitsAnalyzer
|
|
29
29
|
# Public: Returns the tally of commits broken down by weekday and hour.
|
30
30
|
attr_reader :commit_weekdays_hours
|
31
31
|
|
32
|
+
# Public: Returns the lines added/changed by month.
|
33
|
+
attr_reader :lines_by_month
|
34
|
+
|
32
35
|
# Public: Initialize new GitParser object.
|
33
36
|
#
|
34
37
|
# logger - A logger object to display git errors/warnings.
|
@@ -51,6 +54,37 @@ class GitCommitsAnalyzer
|
|
51
54
|
@commit_weekdays_hours[weekday][hour] = 0
|
52
55
|
end
|
53
56
|
end
|
57
|
+
@lines_by_month = {}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Public: Determine if the file is a common library that shouldn't get
|
61
|
+
# counted towards contributions.
|
62
|
+
#
|
63
|
+
# filename - The name of the file to analyze.
|
64
|
+
#
|
65
|
+
# Returns a boolean indicating if the file is a common library.
|
66
|
+
#
|
67
|
+
def self.is_library(filename:)
|
68
|
+
case filename
|
69
|
+
when /jquery-ui-\d+\.\d+\.\d+\.custom(?:\.min)?\.js$/
|
70
|
+
return true
|
71
|
+
when /jquery-\d+\.\d+\.\d+(?:\.min)?\.js$/
|
72
|
+
return true
|
73
|
+
when /jquery\.datepick(?:\.min)?\.js$/
|
74
|
+
return true
|
75
|
+
when /chart\.min\.js$/
|
76
|
+
return true
|
77
|
+
when /jquery\.js$/
|
78
|
+
return true
|
79
|
+
when /jquery-loader\.js$/
|
80
|
+
return true
|
81
|
+
when /qunit\.js$/
|
82
|
+
return true
|
83
|
+
when /d3\.v3(?:\.min)?\.js$/
|
84
|
+
return true
|
85
|
+
else
|
86
|
+
return false
|
87
|
+
end
|
54
88
|
end
|
55
89
|
|
56
90
|
# Public: Determine the type of a file at the given revision of a repo.
|
@@ -158,12 +192,17 @@ class GitCommitsAnalyzer
|
|
158
192
|
commit_weekday = commit_datetime.strftime('%a')
|
159
193
|
@commit_weekdays_hours[commit_weekday][commit_hour] += 1
|
160
194
|
|
195
|
+
# Note: months are zero-padded to allow easy sorting, even if it's more
|
196
|
+
# work for formatting later on.
|
197
|
+
commit_month = commit.date.strftime("%Y-%m")
|
198
|
+
|
161
199
|
# Parse diff and analyze patches to detect language.
|
162
200
|
diff = git_repo.show(commit.sha)
|
163
201
|
diff.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
164
202
|
|
165
203
|
file_properties = git_repo.ls_tree(['-r', commit.sha])
|
166
204
|
|
205
|
+
languages_in_commit = {}
|
167
206
|
patches = GitDiffParser.parse(diff)
|
168
207
|
patches.each do |patch|
|
169
208
|
# Skip submodules.
|
@@ -173,30 +212,45 @@ class GitCommitsAnalyzer
|
|
173
212
|
next if file_properties['blob'].has_key?(patch.file) &&
|
174
213
|
(file_properties['blob'][patch.file][:mode] == '120000')
|
175
214
|
|
215
|
+
# Skip libraries.
|
216
|
+
next if self.class.is_library(filename: patch.file)
|
217
|
+
|
176
218
|
body = patch.instance_variable_get :@body
|
177
219
|
language = self.class.determine_language(filename: patch.file, sha: commit.sha, git_repo: git_repo)
|
178
220
|
next if language.nil?
|
179
221
|
@lines_by_language[language] ||=
|
180
222
|
{
|
181
223
|
'added' => 0,
|
182
|
-
'deleted' => 0
|
224
|
+
'deleted' => 0,
|
225
|
+
'commits' => 0,
|
226
|
+
}
|
227
|
+
languages_in_commit[language] = true
|
228
|
+
|
229
|
+
@lines_by_month[commit_month] ||=
|
230
|
+
{
|
231
|
+
'added' => 0,
|
232
|
+
'deleted' => 0,
|
183
233
|
}
|
184
234
|
|
185
235
|
body.split(/\n/).each do |content|
|
186
236
|
if (/^[+-]/.match(content) && !/^[+-]\s+$/.match(content))
|
187
237
|
if (/^\+/.match(content))
|
188
238
|
@lines_by_language[language]['added'] += 1
|
239
|
+
@lines_by_month[commit_month]['added'] += 1
|
189
240
|
elsif (/^\-/.match(content))
|
190
241
|
@lines_by_language[language]['deleted'] += 1
|
242
|
+
@lines_by_month[commit_month]['deleted'] += 1
|
191
243
|
end
|
192
244
|
end
|
193
245
|
end
|
194
246
|
end
|
195
247
|
|
248
|
+
languages_in_commit.keys.each do |language|
|
249
|
+
@lines_by_language[language]['commits'] += 1
|
250
|
+
end
|
251
|
+
|
196
252
|
# Add to stats for monthly commit count.
|
197
|
-
|
198
|
-
# work for formatting later on.
|
199
|
-
@commits_by_month[commit.date.strftime("%Y-%m")] += 1
|
253
|
+
@commits_by_month[commit_month] += 1
|
200
254
|
|
201
255
|
# Add to stats for total commits count.
|
202
256
|
@commits_total += 1
|
@@ -228,12 +282,29 @@ class GitCommitsAnalyzer
|
|
228
282
|
#
|
229
283
|
def to_json(pretty: true)
|
230
284
|
formatted_commits_by_month = []
|
285
|
+
formatted_lines_by_month = []
|
231
286
|
month_names = Date::ABBR_MONTHNAMES
|
232
287
|
self.get_month_scale.each do |frame|
|
233
288
|
display_key = month_names[frame[1]] + '-' + frame[0].to_s
|
234
289
|
data_key = sprintf('%s-%02d', frame[0], frame[1])
|
290
|
+
|
235
291
|
count = @commits_by_month[data_key]
|
236
|
-
formatted_commits_by_month << {
|
292
|
+
formatted_commits_by_month << {
|
293
|
+
month: display_key,
|
294
|
+
commits: count.to_i,
|
295
|
+
}
|
296
|
+
|
297
|
+
month_added_lines = 0
|
298
|
+
month_deleted_lines = 0
|
299
|
+
if @lines_by_month.key?(data_key)
|
300
|
+
month_added_lines = @lines_by_month[data_key]['added'].to_i
|
301
|
+
month_deleted_lines = @lines_by_month[data_key]['deleted'].to_i
|
302
|
+
end
|
303
|
+
formatted_lines_by_month << {
|
304
|
+
month: display_key,
|
305
|
+
added: month_added_lines,
|
306
|
+
deleted: month_deleted_lines,
|
307
|
+
}
|
237
308
|
end
|
238
309
|
|
239
310
|
data =
|
@@ -243,7 +314,8 @@ class GitCommitsAnalyzer
|
|
243
314
|
commits_by_hour: @commit_hours,
|
244
315
|
commits_by_day: @commit_days,
|
245
316
|
commit_by_weekday_hour: @commit_weekdays_hours,
|
246
|
-
lines_by_language: @lines_by_language
|
317
|
+
lines_by_language: @lines_by_language,
|
318
|
+
lines_by_month: formatted_lines_by_month,
|
247
319
|
}
|
248
320
|
|
249
321
|
if pretty
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-commits-analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Aubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parse git repos and collect commit statistics/data for a given author.
|
14
14
|
email: aubertg@cpan.org
|
@@ -22,7 +22,7 @@ files:
|
|
22
22
|
- lib/git-commits-analyzer/utils.rb
|
23
23
|
homepage: http://rubygems.org/gems/
|
24
24
|
licenses:
|
25
|
-
-
|
25
|
+
- MIT
|
26
26
|
metadata: {}
|
27
27
|
post_install_message:
|
28
28
|
rdoc_options: []
|