Module: Gith::Config

Included in:
Gith
Defined in:
lib/gith/config.rb

Instance Method Summary collapse

Instance Method Details

#configObject



22
23
24
25
26
27
28
# File 'lib/gith/config.rb', line 22

def config
  @config ||= if File.exists?(config_path)
    YAML.load(File.read(config_path))
  else
    error "Config does not exist. Please generate with 'gith config'"
  end
end

#config_pathObject



30
31
32
# File 'lib/gith/config.rb', line 30

def config_path
  @config_path ||= File.expand_path("~/.gith.yml")
end

#generateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gith/config.rb', line 8

def generate
  unless yes_or_no "Config exists.  Overwrite?"
    exit_with "Using existing config".color(:green)
  end if File.exists? config_path

  @config ||= {}

  pivotal_config and github_config and slack_config

  File.open(@config_path, 'w') { |f| f.write(YAML.dump(@config)) }

  success "Config saved"
end

#github_configObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gith/config.rb', line 42

def github_config
       = asks("Github Username: ")
  password  = get_password("Github password: ")
  client    = Octokit::Client.new login: , password: password
  tfa       = asks("Two-factor code: ")
  token     = client.create_authorization(
              scopes:   ["user", "repo"],
              note:     "Gith",
              headers:  { "X-GitHub-OTP" => tfa }).token

  @config[:github_token] = token
end

#pivotal_configObject



34
35
36
# File 'lib/gith/config.rb', line 34

def pivotal_config
  @config[:pivotal_token] = asks("Pivotal Api Token: ")
end

#slack_configObject



38
39
40
# File 'lib/gith/config.rb', line 38

def slack_config
  @config[:slack_token]   = asks("Slack Api Token: ")
end