Skip to content

Instantly share code, notes, and snippets.

@cv
Created Jan 7, 2019
Embed
What would you like to do?
#!/usr/bin/env ruby
require "bundler/inline"
ORG=(ARGV.length == 1 && ARGV[0]) or raise "Usage: pr-queue.rb <org-name>"
gemfile do
source "https://rubygems.org"
gem "octokit"
gem "pry"
end
puts "# Gems installed and loaded"
client = Octokit::Client.new(
access_token: ENV.fetch("GITHUB_TOKEN"),
auto_paginate: true
)
puts "# Github client created"
repo_names = client.org_repos("#{ORG}").map {|repo| repo.name }.sort
puts "# Found #{repo_names.length} repos"
repo_names.inject({}) do |a,e|
pulls = client.pulls("#{ORG}/#{e}", state: "open")
days_outstanding = pulls.map {|pr| (Time.now.to_date.mjd - pr.created_at.to_date.mjd) }.sum
a[e] = [pulls.length, days_outstanding] if days_outstanding > 0
a
end.sort_by {|k, v| v }.each do |k, v|
puts "#{k}, #{v[0]}, #{v[1]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment