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/committer_count.rb
Views: 11766
#!/usr/bin/env ruby12#3# The committer_count.rb is a way to tell who's been active over the last4# given period. It's of course, quite coarse -- someone with 10 commits in a day5# may or may not be more productive than someone with 3, but over long enough6# periods, it's an okay metric to measure involvement with the project, since7# large and small commits will tend to average out.8#9# Note that this includes merge commits by default (which usually means at least10# code review happened, so it's still a measure of work). You can get different11# stats by ignoring merge commits, once option parsing is implemented.12#13# Usage: ./committer_count.rb 2011-01-01 | head -10 # Since a particular date14# ./committer_count.rb 1y | head -10 # Last year15# ./committer_count.rb 6m | head -10 # Last six months16# ./committer_count.rb 12w | head -10 # Last twelve weeks17# ./committer_count.rb 100d | head -10 # Last hundred days18#19#20# History with colors and e-mail addresses (respecting .mailmap):21# git log --pretty=format:"%C(white)%ad %C(yellow)%h %Cblue'%aN' <%aE> %Cgreen%f%Creset" --date=short22#23require 'time'2425class GitLogLine < Struct.new(:date, :hash, :author, :message)26end2728@history = `git log --pretty=format:"%ad %h '%aN' %f" --date=short --date-order`29@recent_history = []30@commits_by_author = {}3132def parse_date(date)33case date34when /([0-9]+)y(ear)?s?/35seconds = $1.to_i* (60*60*24*365.25)36calc_date = (Time.now - seconds).strftime("%Y-%m-%d")37when /([0-9]+)m(onth)?s?/38seconds = $1.to_i* (60*60*24*(365.25 / 12))39calc_date = (Time.now - seconds).strftime("%Y-%m-%d")40when /([0-9]+)w(eek)?s?/41seconds = $1.to_i* (60*60*24*7)42calc_date = (Time.now - seconds).strftime("%Y-%m-%d")43when /([0-9]+)d(ay)?s?/44seconds = $1.to_i* (60*60*24)45calc_date = (Time.now - seconds).strftime("%Y-%m-%d")46else47calc_date = Time.parse(date).strftime("%Y-%m-%d")48end49end5051date = ARGV[0] || "2005-03-22" # A day before the first SVN commit.52calc_date = parse_date(date)5354@history.each_line do |line|55parsed_line = line.match(/^([^\s+]+)\s(.{7,})\s'(.*)'\s(.*)[\r\n]*$/)56next unless parsed_line57break if calc_date == parsed_line[1]58@recent_history << GitLogLine.new(*parsed_line[1,4])59end6061@recent_history.each do |logline|62@commits_by_author[logline.author] ||= []63@commits_by_author[logline.author] << logline.message64end6566puts "Commits since #{calc_date}"67puts "-" * 506869@commits_by_author.sort_by {|k,v| v.size}.reverse.each do |k,v|70puts "%-25s %3d" % [k,v.size]71end72737475