Skip to content

Instantly share code, notes, and snippets.

@JoshuaRogers
Last active December 23, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaRogers/6632481 to your computer and use it in GitHub Desktop.
Save JoshuaRogers/6632481 to your computer and use it in GitHub Desktop.
Placing this script in a Drupal clone and running it will generate a YAML list (contrib.yaml) of all the parsable names listed in the logs. As a note, the script will produce some garbage values. The goal behind it was that it was better to have some incorrect items added than it was to inadvertently leave someone off.
require 'yaml'
class Repository
def messages
`git log --oneline`.split("\n")
end
end
class MessageParser
def initialize(unprocessed_line)
contributor_regex = /by ([[:alnum:]_,\/ -]+)([.;:|-]|'s)/
@matches = unprocessed_line.match contributor_regex
end
def authors
@matches.nil? ? [ ] : split_on_break_words(@matches[1])
end
private
def split_on_break_words(original_line)
original_line.gsub(/( and | et al |\/)/i, ',')
.split(",")
.map(&:strip)
.reject(&:empty?)
end
end
class ContributionCounter
def initialize()
@contributors = Hash.new 0
end
def add(entry)
return if entry.nil?
entry = [ entry ] unless entry.class == Array
entry.each { |person| @contributors[person.downcase] += 1 }
end
def find_by_user(username)
@contributors[username.downcase]
end
def users
@contributors.keys
end
def contributions
@contributors
end
end
repository = Repository.new
contrib_counter = ContributionCounter.new
repository.messages.each { |line| contrib_counter.add MessageParser.new(line).authors }
File.open('contrib.yaml', 'w') { |file| file.write contrib_counter.contributions.to_yaml }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment