CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/module_commits.rb
Views: 11766
1
#!/usr/bin/env ruby
2
3
##
4
# This module requires Metasploit: https://metasploit.com/download
5
# Current source: https://github.com/rapid7/metasploit-framework
6
##
7
8
#
9
# Check the commit history of a module or tree of modules.
10
# and sort by number of commits.
11
#
12
# Usage: tools/module_commits.rb [module dir | module fname]
13
#
14
15
require 'find'
16
17
class GitLogLine < Struct.new(:date, :hash, :author, :message)
18
end
19
20
class CommitHistory < Struct.new(:fname, :total, :authors)
21
end
22
23
msfbase = __FILE__
24
while File.symlink?(msfbase)
25
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
26
end
27
28
dir = ARGV[0] || File.join(msfbase, "modules", "exploits")
29
raise ArgumentError, "Need a filename or directory" unless (dir and File.readable? dir)
30
31
def check_commit_history(fname)
32
33
git_cmd = `git log --pretty=format:"%ad %h '%aN' %f" --date=short --date-order #{fname}`
34
commit_history = []
35
commits_by_author = {}
36
37
git_cmd.each_line do |line|
38
parsed_line = line.match(/^([^\s+]+)\s(.{7,})\s'(.*)'\s(.*)[\r\n]*$/)
39
commit_history << GitLogLine.new(*parsed_line[1,4])
40
end
41
42
commit_history.each do |logline|
43
commits_by_author[logline.author] ||= []
44
commits_by_author[logline.author] << logline.message
45
end
46
47
puts "Commits for #{fname} #{commit_history.size}"
48
puts "-" * 72
49
50
commits_by_author.sort_by {|k,v| v.size}.reverse.each do |k,v|
51
puts "%-25s %3d" % [k,v.size]
52
end
53
54
this_module = CommitHistory.new(fname,commit_history.size,commits_by_author)
55
return this_module
56
57
end
58
59
@module_stats = []
60
61
Find.find(dir) do |fname|
62
next unless fname =~ /rb$/
63
@module_stats << check_commit_history(fname)
64
end
65
66
puts "=" * 72
67
puts "Sorted modules by commit counts"
68
69
@module_stats.sort_by {|m| m.total }.reverse.each do |m|
70
puts "%-60s %d" % [m.fname, m.total]
71
end
72
73