Created
May 22, 2013 11:09
-
-
Save zaki/5626807 to your computer and use it in GitHub Desktop.
pull request stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'date' | |
# SETTINGS | |
PAGE = 1 | |
PER_PAGE = 10 | |
AUTH = "" # basic authentication info | |
REPO = "" # eg zaki/dotfiles | |
class PR | |
attr_accessor :id, :user, :created_at, :closed_at | |
attr_accessor :comments, :commits, :additions, :deletions, :changed_files | |
def initialize(id, user, created_at, closed_at) | |
@id, @user, @add = id, user | |
@created_at = DateTime.parse(created_at) | |
@closed_at = DateTime.parse(closed_at) | |
end | |
def to_s | |
"#{@id},#{@user},#{@created_at.to_s},#{@closed_at.to_s},#{(@closed_at-@created_at).to_f*86400/60},#{@comments},#{@commits},#{@additions},#{@deletions},#{@changed_files}" | |
end | |
def get! | |
pr_txt = %x(curl -s -H "Authorization: Basic #{AUTH}" https://api.github.com/repos/#{REPO}/pulls/#{@id}) | |
pr_json = JSON.parse(pr_txt) | |
@comments = pr_json["comments"] | |
@commits = pr_json["commits"] | |
@additions = pr_json["additions"] | |
@deletions = pr_json["deletions"] | |
@changed_files = pr_json["changed_files"] | |
end | |
def self.all | |
_prs = [] | |
1.upto(PAGE) do |i| | |
puts "Fetching page #{i}" | |
pr_txt = %x(curl -s -H "Authorization: Basic #{AUTH}" https://api.github.com/repos/#{REPO}/pulls\\?state\\=closed\\&per_page\\=#{PER_PAGE}\\&page\\=#{i}) | |
pr_json = JSON.parse(pr_txt) | |
pr_json.each do |pr| | |
if pr.fetch("number") && pr.fetch("user") && pr["user"].fetch("login") && pr["merged_at"] | |
prr = PR.new(pr["number"].to_i, pr["user"]["login"], pr["created_at"], pr["merged_at"]) | |
prr.get! | |
_prs << prr | |
puts "Fetched #{_prs.length} pull requests" if _prs.length % 10 == 0 | |
end | |
end | |
end | |
_prs | |
end | |
end | |
prs = PR.all | |
File.open("pull_requests.csv", "w") do |out| | |
out.puts "PR,AUTHOR,OPENED,CLOSED,TIME,COMMENTS,COMMITS,ADDITIONS,DELETIONS,CHANGED_FILES" | |
prs.each do |pr| | |
out.puts pr.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment