Skip to content

Instantly share code, notes, and snippets.

@ltw
Last active January 9, 2016 04:49
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 ltw/83337e2e4aca6d9ccd0d to your computer and use it in GitHub Desktop.
Save ltw/83337e2e4aca6d9ccd0d to your computer and use it in GitHub Desktop.
Assigner of GitHub PR fairly across multiple reviewers
require 'octokit'
class BetterGitHub
def pulls(organization, options={})
@pulls ||= {}
@pulls[organization] ||= get_pulls(organization, options)
end
def repos(organization)
@repositories ||= {}
@repositories[organization] ||= client.organization_repositories(organization)
end
private
def get_pulls(organization, options={})
print "Fetching repos..." if options[:progress]
repos(organization).map do |repo|
print "." if options[:progress]
repo.rels[:pulls].get.data.select {|x| x.assignee}
end.flatten.sort_by(&:created_at)
ensure
puts " done." if options[:progress]
end
def client
Octokit.auto_paginate = true
@client ||= Octokit::Client.new({login: ::GITHUB_USERNAME, password: ::GITHUB_PASSWORD})
end
end
class GitHubController
def get_pulls_for_user(username, organization, options={})
org_pulls = better_github.pulls(organization, progress: true)
org_pulls.select {|x| x.assignee.login == username}
end
private
def better_github
@better_github ||= BetterGitHub.new
end
end
class PullRequestListView
def self.render_all(username, pull_requests)
<<-PRLV
PRs for #{username}:
Total: #{pull_requests.count}
#{pull_requests.map {|pr| render(pr) }.join("\n")}
----------
PRLV
end
def self.render(pull_request)
"#{pull_request.user.login}: #{pull_request._links.html.href} (#{pull_request.created_at.to_date})"
end
end
source "https://rubygems.org"
gem 'octokit'
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.6)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
multipart-post (2.0.0)
octokit (3.3.1)
sawyer (~> 0.5.3)
sawyer (0.5.5)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
PLATFORMS
ruby
DEPENDENCIES
octokit
require_relative 'assigns'
# Octokit configuration goes here.
GITHUB_USERNAME=
GITHUB_PASSWORD=
ORGANIZATION =
USERNAMES = []
github = GitHubController.new
USERNAMES.each do |username|
puts PullRequestListView.render_all(username, github.get_pulls_for_user(username, ORGANIZATION))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment