Skip to content

Instantly share code, notes, and snippets.

@jdmorlan
Last active October 20, 2015 01:38
Show Gist options
  • Save jdmorlan/ae08e1b676711b9a007f to your computer and use it in GitHub Desktop.
Save jdmorlan/ae08e1b676711b9a007f to your computer and use it in GitHub Desktop.
Figure out who has commited code to a Github repo
# Make sure you gem install http
require 'http'
class Committer
attr_reader :name, :email
def initialize(params)
@name = params["name"]
@email = params["email"]
end
end
class CommitterCollection
include Enumerable
def initialize
@committers = []
end
def add(committer)
if (find_by(:name, committer.name).nil?) && (find_by(:email, committer.email).nil?)
@committers << committer
end
end
def each(&block)
@committers.each do |committer|
block.call(committer)
end
end
def find_by(method, value)
@committers.find { |c| c.send(method) == value }
end
end
class Github
# Repository must be public
def get_committers(owner, repository)
JSON.parse(HTTP.get("https://api.github.com/repos/#{owner}/#{repository}/commits"))
end
def display_committers(owner, repository)
commits = get_committers(owner, repository)
committer_collection = CommitterCollection.new
commits.each do |commit|
commit_author = commit["commit"]["committer"]
committer_collection.add(Committer.new(commit_author))
end
committer_collection.each do |committer|
puts "Name: #{committer.name}, Email: #{committer.email}"
end
end
end
client = Github.new
client.display_committers('tiy-hou-q3-2015-rails', 'musik')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment