Module: Gith::Config
- Included in:
- Gith
- Defined in:
- lib/gith/config.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config_path ⇒ Object
- #generate ⇒ Object
- #github_config ⇒ Object
- #pivotal_config ⇒ Object
- #slack_config ⇒ Object
Instance Method Details
#config ⇒ Object
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_path ⇒ Object
30 31 32 |
# File 'lib/gith/config.rb', line 30 def config_path @config_path ||= File.("~/.gith.yml") end |
#generate ⇒ Object
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_config ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gith/config.rb', line 42 def github_config login = asks("Github Username: ") password = get_password("Github password: ") client = Octokit::Client.new login: login, password: password tfa = asks("Two-factor code: ") token = client.( scopes: ["user", "repo"], note: "Gith", headers: { "X-GitHub-OTP" => tfa }).token @config[:github_token] = token end |
#pivotal_config ⇒ Object
34 35 36 |
# File 'lib/gith/config.rb', line 34 def pivotal_config @config[:pivotal_token] = asks("Pivotal Api Token: ") end |
#slack_config ⇒ Object
38 39 40 |
# File 'lib/gith/config.rb', line 38 def slack_config @config[:slack_token] = asks("Slack Api Token: ") end |