Skip to content

Instantly share code, notes, and snippets.

@thomet
Last active January 23, 2017 12:08
Show Gist options
  • Save thomet/e417ef748febda5823d461d9956c26f9 to your computer and use it in GitHub Desktop.
Save thomet/e417ef748febda5823d461d9956c26f9 to your computer and use it in GitHub Desktop.
BitBar plugin: Not reviewed open Github PR's
#!/usr/bin/env ruby
#
# <bitbar.title>Not reviewed open Github PR's</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Thomas Metzmacher</bitbar.author>
# <bitbar.author.github>thomet</bitbar.author.github>
# <bitbar.desc>Shows all not from you reviewed and open Github PR's for specific users.</bitbar.desc>
# <bitbar.dependencies>ruby</bitbar.dependencies>
#
require 'json'
require 'net/http'
### CONFIG ###
# Create a personal access token: https://github.com/settings/tokens
GITHUB_AUTH_TOKEN = ''
# Your github user name
USER = 'you github name'
# Show only PR's from this users
SQUAD_USERS = %w(put in github user names here)
# Only for repos from this user/company
REPO_USER = 'you github user/organisation name'
# The color for the different PR states
STATE_COLOR = {
'clean' => 'green',
'unstable' => 'yellow',
'dirty' => 'red'
}
### END CONFIG ###
def get_json(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri, {'Authorization' => 'token ' + GITHUB_AUTH_TOKEN})
response = http.request(request)
JSON.parse(response.body)
end
def get_pr_data(url)
get_json(url)['items'].map do |item|
pr = get_json(item['pull_request']['url'])
[item['title'], item['html_url'], STATE_COLOR[pr['mergeable_state']], pr['mergeable']]
end
end
def print_pr_line(pr)
puts "#{pr[0]}#{pr[3] ? '' : ' ⚡'}|href=#{pr[1]} color=#{pr[2]}"
end
open_squad_prs = []
SQUAD_USERS.each do |author|
open_squad_prs += get_pr_data("https://api.github.com/search/issues?q=state:open+type:pr+user:#{REPO_USER}+author:#{author}+-commenter:#{USER}")
end
open_user_prs = []
open_user_prs += get_pr_data("https://api.github.com/search/issues?q=state:open+type:pr+user:#{REPO_USER}+author:#{USER}")
puts "Not Reviewed PR's: #{open_squad_prs.count}, Open PR's: #{open_user_prs.count}"
puts '---'
open_squad_prs.each { |pr| print_pr_line(pr) }
puts '---'
open_user_prs.each { |pr| print_pr_line(pr) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment