Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/modules/module_commits.rb
Views: 11766
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# Check the commit history of a module or tree of modules.9# and sort by number of commits.10#11# Usage: tools/module_commits.rb [module dir | module fname]12#1314require 'find'1516class GitLogLine < Struct.new(:date, :hash, :author, :message)17end1819class CommitHistory < Struct.new(:fname, :total, :authors)20end2122msfbase = __FILE__23while File.symlink?(msfbase)24msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))25end2627dir = ARGV[0] || File.join(msfbase, "modules", "exploits")28raise ArgumentError, "Need a filename or directory" unless (dir and File.readable? dir)2930def check_commit_history(fname)3132git_cmd = `git log --pretty=format:"%ad %h '%aN' %f" --date=short --date-order #{fname}`33commit_history = []34commits_by_author = {}3536git_cmd.each_line do |line|37parsed_line = line.match(/^([^\s+]+)\s(.{7,})\s'(.*)'\s(.*)[\r\n]*$/)38commit_history << GitLogLine.new(*parsed_line[1,4])39end4041commit_history.each do |logline|42commits_by_author[logline.author] ||= []43commits_by_author[logline.author] << logline.message44end4546puts "Commits for #{fname} #{commit_history.size}"47puts "-" * 724849commits_by_author.sort_by {|k,v| v.size}.reverse.each do |k,v|50puts "%-25s %3d" % [k,v.size]51end5253this_module = CommitHistory.new(fname,commit_history.size,commits_by_author)54return this_module5556end5758@module_stats = []5960Find.find(dir) do |fname|61next unless fname =~ /rb$/62@module_stats << check_commit_history(fname)63end6465puts "=" * 7266puts "Sorted modules by commit counts"6768@module_stats.sort_by {|m| m.total }.reverse.each do |m|69puts "%-60s %d" % [m.fname, m.total]70end717273