Last active
January 3, 2019 15:56
-
-
Save Kallin/8382d5cd688481c195e80e2e90732ef0 to your computer and use it in GitHub Desktop.
gives an indication of how much someone has reviewed/commented on someone else's PRs
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 'octokit' | |
require 'pp' | |
def obtain_comment_stats | |
# takes about a minute for 1 months of PRs | |
stats = {} | |
# sample_output = { | |
# "kallin" => { | |
# "adnan" => 24, | |
# "elan" => 13 | |
# }, | |
# "adnan" => { | |
# "kallin" => 32, | |
# "marissa" => 41 | |
# } | |
# } | |
days_of_history = 30 | |
cutoff_time = Time.now - (60 * 60 * 24 * days_of_history) | |
# use your secret token here | |
token = 'xxx' | |
client = Octokit::Client.new(:access_token => token) | |
prs = client.pull_requests('financeit/financeit', {state: 'all'}) | |
# get all the PRs | |
next_response = client.last_response | |
while prs.last.created_at > cutoff_time | |
puts "collecting more PRs back to #{prs.last.created_at}" | |
next_response = next_response.rels[:next].get | |
prs.concat next_response.data | |
end | |
# get stats on each PR | |
prs.each do |pr| | |
puts "processing PR #{pr.number}, from #{pr.created_at}" | |
author = pr.user.login | |
unless stats[author] | |
stats[author] = {} | |
end | |
author_stats = stats[author] | |
pop_stats_for_type(author, author_stats, :review_comments, pr) | |
pop_stats_for_type(author, author_stats, :comments, pr) | |
reviews = client.pull_request_reviews("financeit/financeit", pr.number) | |
reviews.each do |review| | |
reviewer = review.user.login | |
count_colleague(author, author_stats, reviewer) | |
end | |
end | |
stats | |
end | |
def pop_stats_for_type(author, author_stats, comment_type, pr) | |
review_comments = pr.rels[comment_type].get | |
more = true | |
while more | |
data = review_comments.data | |
data.each do |review_comment| | |
commentor = review_comment.user.login | |
count_colleague(author, author_stats, commentor) | |
end | |
next_comments = review_comments.rels[:next] | |
if next_comments | |
review_comments = next_comments.get | |
else | |
more = false | |
end | |
end | |
end | |
def count_colleague(author, author_stats, colleague) | |
if author != colleague | |
unless author_stats[colleague] | |
author_stats[colleague] = 0 | |
end | |
commentor_stats = author_stats[colleague] | |
author_stats[colleague] = commentor_stats + 1 | |
end | |
end | |
def print_stats(stats) | |
stats.each do |k,v| | |
puts "\n" | |
puts k | |
sorted_vs = v.sort_by {|k2,v2| -v2} | |
sorted_vs.each do |k2,v2| | |
puts "\t#{k2} : #{v2}" | |
end | |
end | |
end | |
stats = obtain_comment_stats | |
print_stats(stats) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment