Method: GitReflow::GitServer::BitBucket#authenticate

Defined in:
lib/git_reflow/git_server/bit_bucket.rb

#authenticate(options = {silent: false}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/git_reflow/git_server/bit_bucket.rb', line 55

def authenticate(options = {silent: false})
  begin
    if connection and self.class.api_key_setup?
      unless options[:silent]
        GitReflow.say "\nYour BitBucket account was already setup with:"
        GitReflow.say "\tUser Name: #{self.class.user}"
      end
    else
      self.class.user = options[:user] || ask("Please enter your BitBucket username: ")
      GitReflow.say "\nIn order to connect your BitBucket account,"
      GitReflow.say "you'll need to generate an API key for your team"
      GitReflow.say "Visit #{self.class.site_url}/account/user/#{self.class.remote_user}/api-key/, to generate it\n"
      self.class.api_key = ask("Please enter your team's API key: ")
      connection.repos.all(self.class.remote_user).count
      GitReflow.say "Connected to BitBucket\!", :success
    end
  rescue ::BitBucket::Error::Unauthorized => e
    GitReflow::Config.unset('bitbucket.api-key', local: self.class.project_only?)
    GitReflow.say "Invalid API key for team #{self.class.remote_user}.", :error
  end
end