Module: GithubTools::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/github_tools/configuration.rb

Instance Method Summary collapse

Instance Method Details

#create_tokenObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/github_tools/configuration.rb', line 11

def create_token
  print 'Username:'
  username = gets.strip
  print 'Password (never saved):'
  password = STDIN.noecho(&:gets).strip
  client = Octokit::Client.new(:login => username, :password => password)
  response = client.create_authorization(
    :scopes => [:repo],
    :note => 'github_tools',
    :note_url =>'https://github.com/ivantsepp/github_tools')
  token = response[:token]
  save_token(token)
  token
end

#remoteObject



30
31
32
33
34
35
# File 'lib/github_tools/configuration.rb', line 30

def remote
  url = `git config --get remote.origin.url`.strip
  url = 'ssh://' + url if url.include?('@')
  url.gsub!('.git', '')
  Octokit::Repository.from_url(url)
end

#save_token(token) ⇒ Object



26
27
28
# File 'lib/github_tools/configuration.rb', line 26

def save_token(token)
  `git config --global githubtools.token #{token}`
end

#tokenObject



5
6
7
8
9
# File 'lib/github_tools/configuration.rb', line 5

def token
  token = `git config githubtools.token`.strip
  token = create_token if token.empty?
  token
end