CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/committer_count.rb
Views: 1904
1
#!/usr/bin/env ruby
2
3
#
4
# The committer_count.rb is a way to tell who's been active over the last
5
# given period. It's of course, quite coarse -- someone with 10 commits in a day
6
# may or may not be more productive than someone with 3, but over long enough
7
# periods, it's an okay metric to measure involvement with the project, since
8
# large and small commits will tend to average out.
9
#
10
# Note that this includes merge commits by default (which usually means at least
11
# code review happened, so it's still a measure of work). You can get different
12
# stats by ignoring merge commits, once option parsing is implemented.
13
#
14
# Usage: ./committer_count.rb 2011-01-01 | head -10 # Since a particular date
15
# ./committer_count.rb 1y | head -10 # Last year
16
# ./committer_count.rb 6m | head -10 # Last six months
17
# ./committer_count.rb 12w | head -10 # Last twelve weeks
18
# ./committer_count.rb 100d | head -10 # Last hundred days
19
#
20
#
21
# History with colors and e-mail addresses (respecting .mailmap):
22
# git log --pretty=format:"%C(white)%ad %C(yellow)%h %Cblue'%aN' <%aE> %Cgreen%f%Creset" --date=short
23
#
24
require 'time'
25
26
class GitLogLine < Struct.new(:date, :hash, :author, :message)
27
end
28
29
@history = `git log --pretty=format:"%ad %h '%aN' %f" --date=short --date-order`
30
@recent_history = []
31
@commits_by_author = {}
32
33
def parse_date(date)
34
case date
35
when /([0-9]+)y(ear)?s?/
36
seconds = $1.to_i* (60*60*24*365.25)
37
calc_date = (Time.now - seconds).strftime("%Y-%m-%d")
38
when /([0-9]+)m(onth)?s?/
39
seconds = $1.to_i* (60*60*24*(365.25 / 12))
40
calc_date = (Time.now - seconds).strftime("%Y-%m-%d")
41
when /([0-9]+)w(eek)?s?/
42
seconds = $1.to_i* (60*60*24*7)
43
calc_date = (Time.now - seconds).strftime("%Y-%m-%d")
44
when /([0-9]+)d(ay)?s?/
45
seconds = $1.to_i* (60*60*24)
46
calc_date = (Time.now - seconds).strftime("%Y-%m-%d")
47
else
48
calc_date = Time.parse(date).strftime("%Y-%m-%d")
49
end
50
end
51
52
date = ARGV[0] || "2005-03-22" # A day before the first SVN commit.
53
calc_date = parse_date(date)
54
55
@history.each_line do |line|
56
parsed_line = line.match(/^([^\s+]+)\s(.{7,})\s'(.*)'\s(.*)[\r\n]*$/)
57
next unless parsed_line
58
break if calc_date == parsed_line[1]
59
@recent_history << GitLogLine.new(*parsed_line[1,4])
60
end
61
62
@recent_history.each do |logline|
63
@commits_by_author[logline.author] ||= []
64
@commits_by_author[logline.author] << logline.message
65
end
66
67
puts "Commits since #{calc_date}"
68
puts "-" * 50
69
70
@commits_by_author.sort_by {|k,v| v.size}.reverse.each do |k,v|
71
puts "%-25s %3d" % [k,v.size]
72
end
73
74
75