class Configuration
Constants
- FILENAME
Public Instance Methods
access_token()
click to toggle source
# File lib/merrow/configuration.rb, line 9 def access_token if !data['access_token'] data['access_token'] = create_access_token save(data) end data['access_token'] end
repos()
click to toggle source
# File lib/merrow/configuration.rb, line 17 def repos data["repos"] || data[:repos] || [] end
Private Instance Methods
configuration_file()
click to toggle source
# File lib/merrow/configuration.rb, line 60 def configuration_file config_file = File.join(Dir.home, FILENAME) if File.exist?(config_file) config_file else puts "Config file #{config_file}, not found. You need at least add one repository, what repository are you interested in?" puts "(format is user/repo like rails/rails or JordiPolo/merrow):" repo = gets.chomp if repo.match(/.*\/.*/) File.open(config_file,'w+'){|file| file.write( {repos: [*repo]}.to_yaml)} config_file else puts "Repo format not valid, run the tool again, you need to provide username/reponame like JordiPolo/merrow" exit(-1) end end end
create_access_token()
click to toggle source
# File lib/merrow/configuration.rb, line 24 def create_access_token puts "There is no access token configured in Merrow. You need to create one to access your repositories" puts "You will need to provide your username and password. This will be only asked once to create the access token" puts "The username and password will not be stored anywhere" puts "What is your username for Github?" username = gets.chomp puts "What is your password for Github? (your input is hidden)" password = STDIN.noecho(&:gets).chomp token_name = "Token used by Merrow" client = Octokit::Client.new login: username, password: password auth = client.create_authorization(scopes: ["repo", "public_repo", "user"], note: token_name) puts "A new token has been created for your user with the name #{auth[:app][:name]}" auth[:token] rescue Octokit::Unauthorized => e puts "Authourization failed, user or password wrong?" exit(-1) rescue Octokit::OneTimePasswordRequired => e puts "Your account requires Two-factor authentication." puts "Provide your two-factor token, you will need this only once (input hidden):" token = STDIN.noecho(&:gets).chomp auth = client.create_authorization(scopes: ["repo", "public_repo", "user"], headers: { "X-GitHub-OTP" => token}, note: token_name) auth[:token] end
data()
click to toggle source
# File lib/merrow/configuration.rb, line 56 def data @data ||= YAML.load_file(configuration_file) end
save(data)
click to toggle source
# File lib/merrow/configuration.rb, line 50 def save(data) File.open(configuration_file,'w') do |file| file.write data.to_yaml end end