Skip to content

Instantly share code, notes, and snippets.

@pedro
Last active December 27, 2015 13:19
Show Gist options
  • Save pedro/7332661 to your computer and use it in GitHub Desktop.
Save pedro/7332661 to your computer and use it in GitHub Desktop.
Quick hacky script to rank closed pull requests on a repo in hopes to answers "what happened last year?". Requires gems octokit and peach.
require "rubygems"
require "octokit"
require "peach"
# warning! this will make a crapton of requests under your account.
# you might want to review/tweak the values below, or disable
# auto_paginate to test things first.
# get an access token at https://github.com/settings/tokens/new
token = ENV["TOKEN"] || abort("missing TOKEN")
repo = ENV["REPO"] || abort("missing REPO. eg: pedro/devdigest")
t = Time.now
since = Time.mktime(t.year-1, t.month, t.day)
def score(pull)
(pull.changed_files * 3) + (pull.comments * 2) + (pull.additions * 0.1) + (pull.deletions * 0.2)
end
client = Octokit::Client.new access_token: token, auto_paginate: true
# listing pull requests in Octokit is not paginating properly atm.
# See: https://github.com/octokit/octokit.rb/pull/335
pulls = client.paginate("repos/#{repo}/pulls", state: "closed").pmap(24) do |pull|
next if pull.created_at < since
# fetch info so we have access to changed_files, comments, and more:
client.pull_request(repo, pull.number)
end.compact
pulls.sort_by! do |pull|
score(pull)
end.reverse!
pulls.each do |pull|
break if score(pull) < 8
puts "- #{pull.title} ##{pull.number} (#{score(pull).to_i})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment