Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'io/console'
- require 'octokit'
- require 'netrc'
- GITHUB_API_URL = "api.github.com"
- def clear_github_netrc
- n = Netrc.read
- n.delete(GITHUB_API_URL)
- n.save
- end
- def build_github_netrc
- n = Netrc.read
- puts "Please add your Github credentials"
- print "login : "
- username = gets.chomp
- print "password : "
- password = STDIN.noecho(&:gets)
- puts ""
- n[GITHUB_API_URL] = username, password
- n.save
- end
- def github_client
- unless Netrc.read[GITHUB_API_URL]
- build_github_netrc
- end
- begin
- client = Octokit::Client.new(netrc: true)
- puts "@@ Connected to Github API as #{client.user[:login]} @@"
- return client
- rescue Octokit::Unauthorized
- puts "Github connection failed, please retry..."
- clear_github_netrc
- github_client
- end
- end
- GITHUB_CLIENT = github_client
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement