Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement