Skip to content

Instantly share code, notes, and snippets.

@LOZORD
Created August 20, 2016 23:42
Show Gist options
  • Save LOZORD/3dd6c549d564816693e3cb00dfdaf261 to your computer and use it in GitHub Desktop.
Save LOZORD/3dd6c549d564816693e3cb00dfdaf261 to your computer and use it in GitHub Desktop.
A Ruby script for seeing the number of issues across a GitHub organization
#!/usr/bin/env ruby
# be sure to run `gem install octokit`
require 'octokit'
# `io/console` does not need to be installed, just required
require 'io/console'
def get_input(message, hide_entry = false)
print message + '? '
if hide_entry
input = STDIN.noecho(&:gets).chomp
puts
else
input = gets.chomp
end
return input
end
def get_client(username, password)
Octokit::Client.new(login: username, password: password)
end
def welcome_client(client)
begin
login = client.login
org_names = client.orgs.map { |org| org[:login] }
rescue
abort 'Bad username or password'
else
puts "Welcome #{ login }!"
puts "You have #{ org_names.size } org(s)"
org_names.sort.each do |org_name|
puts "* #{ org_name }"
end
end
end
def get_org_issues(client, org_name)
begin
org_repos = client.org_repos(org_name)
rescue
abort 'Bad organization name'
else
return org_repos.map do |repo|
{ name: repo[:full_name], count: repo[:open_issues_count] }
end
end
end
def main
username = get_input('Username')
password = get_input('Password', true)
client = get_client(username, password)
welcome_client(client)
org_name = get_input('Org Name')
issues = get_org_issues(client, org_name)
issues
.sort_by { |issue| issue[:name] }
.each do |issue|
if issue[:count] > 0
puts "! [#{ issue[:name] }]: #{ issue[:count] } issue(s)"
else
puts " [#{ issue[:name] }]: No issues"
end
end
end
if __FILE__ == $PROGRAM_NAME
main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment