git-stats 0.1.1 → 0.1.2
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/Gemfile.lock +1 -1
- data/lib/git/stats.rb +2 -2
- data/lib/git/stats/commit.rb +44 -0
- data/lib/git/stats/repo.rb +38 -0
- data/lib/git/stats/statistic.rb +61 -0
- data/lib/git/stats/version.rb +1 -1
- metadata +4 -2
- data/lib/git/stats/base.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b7dae0e9364089ee8a05d2ed6d1e2ea164d5bfa10973aef29268fe0a88dfdc
|
4
|
+
data.tar.gz: 742998da77f83602e50d7b6523250d981d3b54c0f77c63a99b13e07e03db84d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92327c63a0191d9ac81e89ae25dfb52198828b301069624cda916830ab910ad7f4ec7fb39d98dce2fc44a0f45ac85d114845b93e41e6d402c0aa6aaac49aa28e
|
7
|
+
data.tar.gz: 7dcc522334169f9f0101d41c1f2de776f77b3cb48bd9ad9fe6f5185557fc1e0572ddabd1271d15d9723f54dd0a33ef123526d9ec93489f356dadad654d256efb
|
data/Gemfile.lock
CHANGED
data/lib/git/stats.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "git/stats/version"
|
2
|
-
require "git/stats/
|
2
|
+
require "git/stats/statistic"
|
3
3
|
|
4
4
|
module Git
|
5
5
|
module Stats
|
@@ -8,7 +8,7 @@ module Git
|
|
8
8
|
class BranchNotFound < StandardError; end
|
9
9
|
|
10
10
|
def self.statistic(folder, branch = "develop", options = {})
|
11
|
-
stats = Git::Stats::
|
11
|
+
stats = Git::Stats::Statistic.statistic(folder, branch, options)
|
12
12
|
yield stats if block_given?
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
module Git
|
4
|
+
module Stats
|
5
|
+
class Commit
|
6
|
+
attr_accessor :repo, :hash, :author_email, :date, :title, :stats
|
7
|
+
|
8
|
+
def initialize(repo, params)
|
9
|
+
@repo = repo
|
10
|
+
@hash = params[:commit_hash]
|
11
|
+
@author_email = params[:author_email]
|
12
|
+
@date = DateTime.parse(params[:commit_date], false).to_date
|
13
|
+
@title = params[:commit_title]
|
14
|
+
end
|
15
|
+
|
16
|
+
def stats
|
17
|
+
@stats ||= commit_stat
|
18
|
+
end
|
19
|
+
|
20
|
+
def commit_stat
|
21
|
+
result = {
|
22
|
+
files: 0,
|
23
|
+
insertions: 0,
|
24
|
+
deletions: 0
|
25
|
+
}
|
26
|
+
|
27
|
+
info = `cd #{@repo.folder} && git checkout #{repo.branch} > /dev/null 2>&1 && git show --stat #{@hash}`.split("\n").last.split(", ").map(&:strip)
|
28
|
+
info.each do |e|
|
29
|
+
if e =~ /^(\d+)\s(.+)$/
|
30
|
+
if $2.include?("file")
|
31
|
+
result[:files] = $1.to_i
|
32
|
+
elsif $2.include?("insertions")
|
33
|
+
result[:insertions] = $1.to_i
|
34
|
+
else
|
35
|
+
result[:deletions] = $1.to_i
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "git/stats/commit"
|
2
|
+
|
3
|
+
module Git
|
4
|
+
module Stats
|
5
|
+
class Repo
|
6
|
+
attr_accessor :folder, :branch
|
7
|
+
|
8
|
+
def initialize(folder, branch)
|
9
|
+
# TODO: Check folder
|
10
|
+
@folder = folder
|
11
|
+
# TODO: Check branch
|
12
|
+
@branch = branch || "develop"
|
13
|
+
end
|
14
|
+
|
15
|
+
def commits
|
16
|
+
result = `cd #{@folder} && git checkout #{@branch} > /dev/null 2>&1 && git log --pretty=format:"%h | %ae | %ci | %s"`.split("\n")
|
17
|
+
result.map do |line|
|
18
|
+
next unless line =~ /^\S+\s\|\s.+$/
|
19
|
+
|
20
|
+
commit_hash, author_email, commit_date, commit_title = line.split(" | ")
|
21
|
+
next if commit_title.include?("Merge branch")
|
22
|
+
|
23
|
+
Commit.new(self,
|
24
|
+
{
|
25
|
+
commit_hash: commit_hash,
|
26
|
+
author_email: author_email,
|
27
|
+
commit_date: commit_date,
|
28
|
+
commit_title: commit_title
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
def authors
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "date"
|
2
|
+
require "git/stats/repo"
|
3
|
+
|
4
|
+
module Git
|
5
|
+
module Stats
|
6
|
+
class Statistic
|
7
|
+
attr_accessor :folder, :branch, :options
|
8
|
+
|
9
|
+
def initialize(folder, branch, options = {})
|
10
|
+
# TODO: Check folder
|
11
|
+
@folder = folder
|
12
|
+
# TODO: Check branch
|
13
|
+
@branch = branch || "develop"
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def statistic
|
18
|
+
result = {}
|
19
|
+
|
20
|
+
stats = filter_commits.group_by { |commit| commit.author_email }
|
21
|
+
stats.each do |author, commits|
|
22
|
+
month_stats = commits.group_by { |c| c.date.strftime("%Y-%m") }
|
23
|
+
info = {}
|
24
|
+
month_stats.each do |month, value|
|
25
|
+
info[month] = {
|
26
|
+
commits: value.length,
|
27
|
+
files: 0,
|
28
|
+
insertions: 0,
|
29
|
+
deletions: 0
|
30
|
+
}
|
31
|
+
value.each do |c|
|
32
|
+
info[month][:files] += c.stats[:files]
|
33
|
+
info[month][:insertions] += c.stats[:insertions]
|
34
|
+
info[month][:deletions] += c.stats[:deletions]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
result[author] = info
|
38
|
+
end
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def filter_commits
|
44
|
+
repo = Repo.new(@folder, @branch)
|
45
|
+
commits = repo.commits
|
46
|
+
|
47
|
+
if options[:start_date]
|
48
|
+
commits = commits.select { |commit| commit.date >= options[:start_date] }
|
49
|
+
end
|
50
|
+
|
51
|
+
commits
|
52
|
+
end
|
53
|
+
|
54
|
+
class << self
|
55
|
+
def statistic(folder, branch, options = {})
|
56
|
+
new(folder, branch, options).statistic
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/git/stats/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nghia Le Van
|
@@ -72,7 +72,9 @@ files:
|
|
72
72
|
- bin/setup
|
73
73
|
- git-stats.gemspec
|
74
74
|
- lib/git/stats.rb
|
75
|
-
- lib/git/stats/
|
75
|
+
- lib/git/stats/commit.rb
|
76
|
+
- lib/git/stats/repo.rb
|
77
|
+
- lib/git/stats/statistic.rb
|
76
78
|
- lib/git/stats/version.rb
|
77
79
|
homepage: https://bunbusoft.com
|
78
80
|
licenses:
|
data/lib/git/stats/base.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module Git
|
4
|
-
module Stats
|
5
|
-
class Base
|
6
|
-
attr_accessor :folder, :branch, :options
|
7
|
-
|
8
|
-
def initialize(folder, branch, options = {})
|
9
|
-
# TODO: Check folder
|
10
|
-
@folder = folder
|
11
|
-
# TODO: Check branch
|
12
|
-
@branch = branch || "develop"
|
13
|
-
@options = options
|
14
|
-
end
|
15
|
-
|
16
|
-
def statistic
|
17
|
-
result = {}
|
18
|
-
|
19
|
-
stats = all_commits.group_by { |commit| commit[:author_email] }
|
20
|
-
stats.each do |author, commits|
|
21
|
-
month_stats = commits.group_by { |c| c[:commit_date].strftime("%Y-%m") }
|
22
|
-
info = {}
|
23
|
-
month_stats.each do |month, value|
|
24
|
-
info[month] = {
|
25
|
-
commits: value.length,
|
26
|
-
files: 0,
|
27
|
-
insertions: 0,
|
28
|
-
deletions: 0
|
29
|
-
}
|
30
|
-
value.each do |c|
|
31
|
-
info[month][:files] += c[:stats][:files]
|
32
|
-
info[month][:insertions] += c[:stats][:insertions]
|
33
|
-
info[month][:deletions] += c[:stats][:deletions]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
result[author] = info
|
37
|
-
end
|
38
|
-
|
39
|
-
result
|
40
|
-
end
|
41
|
-
|
42
|
-
def commit_stat commit_hash
|
43
|
-
result = {
|
44
|
-
files: 0,
|
45
|
-
insertions: 0,
|
46
|
-
deletions: 0
|
47
|
-
}
|
48
|
-
|
49
|
-
info = `cd #{folder} && git checkout #{branch} > /dev/null 2>&1 && git show --stat #{commit_hash}`.split("\n").last.split(", ").map(&:strip)
|
50
|
-
info.each do |e|
|
51
|
-
if e =~ /^(\d+)\s(.+)$/
|
52
|
-
if $2.include?("file")
|
53
|
-
result[:files] = $1.to_i
|
54
|
-
elsif $2.include?("insertions")
|
55
|
-
result[:insertions] = $1.to_i
|
56
|
-
else
|
57
|
-
result[:deletions] = $1.to_i
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
result
|
63
|
-
end
|
64
|
-
|
65
|
-
def all_commits
|
66
|
-
logs = `cd #{folder} && git checkout #{branch} > /dev/null 2>&1 && git log --pretty=format:"%h | %ae | %ci | %s"`.split("\n")
|
67
|
-
logs.map do |line|
|
68
|
-
next unless line =~ /^\S+\s\|\s.+$/
|
69
|
-
|
70
|
-
info = line.split(" | ")
|
71
|
-
commit_date = DateTime.parse(info[2], false).to_date
|
72
|
-
commit_name = info[3]
|
73
|
-
next if commit_name.include?("Merge branch")
|
74
|
-
next if options[:start_date] && commit_date < options[:start_date]
|
75
|
-
|
76
|
-
stats = commit_stat(info[0])
|
77
|
-
{
|
78
|
-
commit_hash: info[0],
|
79
|
-
author_email: info[1],
|
80
|
-
commit_date: commit_date,
|
81
|
-
stats: stats
|
82
|
-
}
|
83
|
-
end.compact
|
84
|
-
end
|
85
|
-
|
86
|
-
class << self
|
87
|
-
def statistic(folder, branch, options = {})
|
88
|
-
new(folder, branch, options).statistic
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|