Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'io/console'
  3. require 'octokit'
  4. require 'netrc'
  5.  
  6. GITHUB_API_URL = "api.github.com"
  7.  
  8. def clear_github_netrc
  9. n = Netrc.read
  10. n.delete(GITHUB_API_URL)
  11. n.save
  12. end
  13.  
  14. def build_github_netrc
  15. n = Netrc.read
  16. puts "Please add your Github credentials"
  17. print "login : "
  18. username = gets.chomp
  19. print "password : "
  20. password = STDIN.noecho(&:gets)
  21. puts ""
  22. n[GITHUB_API_URL] = username, password
  23. n.save
  24. end
  25.  
  26. def github_client
  27. unless Netrc.read[GITHUB_API_URL]
  28. build_github_netrc
  29. end
  30. begin
  31. client = Octokit::Client.new(netrc: true)
  32. puts "@@ Connected to Github API as #{client.user[:login]} @@"
  33. return client
  34. rescue Octokit::Unauthorized
  35. puts "Github connection failed, please retry..."
  36. clear_github_netrc
  37. github_client
  38. end
  39. end
  40.  
  41. GITHUB_CLIENT = github_client
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement