Skip to content

Instantly share code, notes, and snippets.

@Supernats
Created December 5, 2014 04:30
Show Gist options
  • Select an option

  • Save Supernats/b03e7c0d105d61d7f66c to your computer and use it in GitHub Desktop.

Select an option

Save Supernats/b03e7c0d105d61d7f66c to your computer and use it in GitHub Desktop.
require 'json'
module GitHelper
def get_tag(steps: 1)
tag = `git tag -l`.split("\n")[-steps]
end
def the_goods since: get_tag
`git shortlog #{since}..HEAD`
end
def sanitize(steps: 1)
tag = get_tag(steps: steps)
goods = the_goods(since: tag)
lines = goods.split("\n")
lines.reject { |line| line.include?("Merge pull request") }
.map { |line| line.author? ? line.mine_author : line }
end
def process(steps: 1)
lines = sanitize(steps: steps)
report = {}
current_author = nil
lines.each do |line|
next if line.empty?
if line.author?
current_author = line.mine_author
else
report[current_author] ||= []
report[current_author] << line.strip
end
end
report
end
end
class ScoreCard
include GitHelper
attr_accessor :players
def initialize(innings: 1)
score_game(innings)
end
def score_game(steps)
@players ||= []
replay = process steps: steps
replay.each do |player, contributions|
@players << Player.new(name: player, contributions: contributions)
end
end
end
class Player
attr_accessor :name, :contributions
def initialize(name: nil, contributions: nil)
raise MissingArgumentsError unless name && contributions
@name = name
@contributions = contributions
end
def score
contributions.count
end
end
class String
def commit?
self[0] == ' '
end
def author?
!empty? && self[0].match(/^[[:alpha:]]$/)
end
def mine_author
self.sub /\s*\(\d+\)\:$/, ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment