git-stats 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: d73a8d581f651156a6c70265943a8c6c3aa93ae2780d3a47837f8a0dc09fdfba
4
- data.tar.gz: 11d39c0c84a4f77de8e1714b8d2282a57985ec789b055ee02debd7c7c3b764a5
3
+ metadata.gz: 15b7dae0e9364089ee8a05d2ed6d1e2ea164d5bfa10973aef29268fe0a88dfdc
4
+ data.tar.gz: 742998da77f83602e50d7b6523250d981d3b54c0f77c63a99b13e07e03db84d7
5
5
  SHA512:
6
- metadata.gz: af46666af73e0ee7211ecc8408fcfcc3bc24a33193db4537020d5ca1a0ce1fddb7807e2d10e918c1e1d7581370a2298f44fb3a375cf2ab9407b2897df7287258
7
- data.tar.gz: f8d8f2090689d157e7dc1cdaf496fee7e8c7a9e3b6bdd53ed58909669b1f25cba02fbeea3f81946797dfa3310533f962036b915aeae5191d4d764839c7f05330
6
+ metadata.gz: 92327c63a0191d9ac81e89ae25dfb52198828b301069624cda916830ab910ad7f4ec7fb39d98dce2fc44a0f45ac85d114845b93e41e6d402c0aa6aaac49aa28e
7
+ data.tar.gz: 7dcc522334169f9f0101d41c1f2de776f77b3cb48bd9ad9fe6f5185557fc1e0572ddabd1271d15d9723f54dd0a33ef123526d9ec93489f356dadad654d256efb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-stats (0.1.0)
4
+ git-stats (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/git/stats.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "git/stats/version"
2
- require "git/stats/base"
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::Base.statistic(folder, branch, options)
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
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Stats
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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.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/base.rb
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:
@@ -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