-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.rb
executable file
·83 lines (75 loc) · 2.16 KB
/
commit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env ruby
##
#
# This script fetch the number of commits of each author passed as arg
# of the program
#
# TODO: Automatically retrieve the authors from a git log
#
##
require 'colorize'
require_relative 'git_utils'
def extract_options
options = Hash.new
ARGV.each do |av|
index = av.sub(/^--/, '')
options[index] = true
end
options
end
authors = Git::get_authors_from_log
options = extract_options
c_h = Hash.new
authors.each do |author|
if options['email']
index = "#{author[:name]} <#{author[:email]}>"
else
index = author[:name]
end
c_h[index] = Integer(`git log | grep 'Author: #{index}' | wc -l`)
end
m_c = c_h.values.max
min_c = c_h.values.min
a_c = 0
c_h.each do |_, value|
a_c += value
end
t_c = a_c
a_c /= c_h.count
puts "\n\n"
puts '-------------------------------------------------------------------------'
puts '------------------------------ General ----------------------------------'
puts '-------------------------------------------------------------------------'
puts
puts "Nombre total de commits: #{t_c}".yellow
print 'Moyenne de commit par personne : '.yellow
puts "#{a_c} (#{(t_c - m_c) / c_h.count} sans le 1er)".yellow
puts "Plus grand nombre de commits : #{m_c} (#{c_h.key(m_c)})".green
puts "Plus petit nombre de commits : #{min_c} (#{c_h.key(min_c)})".red
puts "\n\n"
puts '-------------------------------------------------------------------------'
puts '------------------------------ Personnal --------------------------------'
puts '-------------------------------------------------------------------------'
puts
i = 1
c_h2 = c_h.clone
while c_h2.count > 0
max = c_h2.values.max
print "#{i} - #{c_h2.key(max)} avec #{max} commits ("
c_h2.delete(c_h2.key(max))
percentage = max * 100 / t_c rescue 0
if percentage >= 15
print "#{percentage}% du total".green
elsif percentage >= 5
print "#{percentage}% du total".yellow
else
print "#{percentage}% du total".red
end
if c_h2.count > 0
diff = Float(max) / Float(c_h2.values.max)
print diff >= 3 ? " soit #{diff.round(1)} fois plus que le suivant".green :
" soit #{diff.round(1)} fois plus que le suivant"
end
puts ')'
i += 1
end