Advertisement
Guest User

Untitled

a guest
Aug 20th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # be sure to run `gem install octokit`
  3. require 'octokit'
  4. # `io/console` does not need to be installed, just required
  5. require 'io/console'
  6.  
  7. def get_input(message, hide_entry = false)
  8. print message + '? '
  9.  
  10. if hide_entry
  11. input = STDIN.noecho(&:gets).chomp
  12. puts
  13. else
  14. input = gets.chomp
  15. end
  16.  
  17. return input
  18. end
  19.  
  20. def get_client(username, password)
  21. Octokit::Client.new(login: username, password: password)
  22. end
  23.  
  24. def welcome_client(client)
  25. begin
  26. login = client.login
  27. org_names = client.orgs.map { |org| org[:login] }
  28. rescue
  29. abort 'Bad username or password'
  30. else
  31. puts "Welcome #{ login }!"
  32. puts "You have #{ org_names.size } org(s)"
  33.  
  34. org_names.sort.each do |org_name|
  35. puts "* #{ org_name }"
  36. end
  37. end
  38. end
  39.  
  40. def get_org_issues(client, org_name)
  41. begin
  42. org_repos = client.org_repos(org_name)
  43. rescue
  44. abort 'Bad organization name'
  45. else
  46. return org_repos.map do |repo|
  47. { name: repo[:full_name], count: repo[:open_issues_count] }
  48. end
  49. end
  50. end
  51.  
  52. def main
  53. username = get_input('Username')
  54.  
  55. password = get_input('Password', true)
  56.  
  57. client = get_client(username, password)
  58.  
  59. welcome_client(client)
  60.  
  61. org_name = get_input('Org Name')
  62.  
  63. issues = get_org_issues(client, org_name)
  64.  
  65. issues
  66. .sort_by { |issue| issue[:name] }
  67. .each do |issue|
  68. if issue[:count] > 0
  69. puts "! [#{ issue[:name] }]: #{ issue[:count] } issue(s)"
  70. else
  71. puts " [#{ issue[:name] }]: No issues"
  72. end
  73. end
  74. end
  75.  
  76. if __FILE__ == $PROGRAM_NAME
  77. main
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement