Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/module_commits.rb
19849 views
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
25
while File.symlink?(msfbase)
26
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
27
end
28
msfbase = File.expand_path(File.join(File.dirname(msfbase), '..', '..'))
29
30
dir = ARGV[0] || File.join(msfbase, "modules", "exploits")
31
raise ArgumentError, "Need a filename or directory" unless (dir and File.readable? dir)
32
33
def check_commit_history(fname)
34
35
git_cmd = `git log --pretty=format:"%ad %h '%aN' %f" --date=short --date-order #{fname}`
36
commit_history = []
37
commits_by_author = {}
38
39
git_cmd.each_line do |line|
40
parsed_line = line.match(/^([^\s+]+)\s(.{7,})\s'(.*)'\s(.*)[\r\n]*$/)
41
commit_history << GitLogLine.new(*parsed_line[1,4])
42
end
43
44
commit_history.each do |logline|
45
commits_by_author[logline.author] ||= []
46
commits_by_author[logline.author] << logline.message
47
end
48
49
puts "Commits for #{fname} #{commit_history.size}"
50
puts "-" * 72
51
52
commits_by_author.sort_by {|k,v| v.size}.reverse.each do |k,v|
53
puts "%-25s %3d" % [k,v.size]
54
end
55
56
this_module = CommitHistory.new(fname,commit_history.size,commits_by_author)
57
return this_module
58
59
end
60
61
@module_stats = []
62
63
Find.find(dir) do |fname|
64
next unless fname =~ /\.(rb|py)$/ # be either ruby or python
65
next unless File.file?(fname) && File.readable?(fname)
66
@module_stats << check_commit_history(fname)
67
end
68
69
puts "=" * 72
70
puts "Sorted modules by commit counts"
71
72
@module_stats.sort_by {|m| m.total }.reverse.each do |m|
73
puts "%-60s %d" % [m.fname, m.total]
74
end
75
76