Class: DotenvToCI
- Inherits:
-
Object
- Object
- DotenvToCI
- Defined in:
- lib/dotenv_to_ci.rb
Instance Attribute Summary collapse
-
#dotenvs ⇒ Object
Returns the value of attribute dotenvs.
-
#project ⇒ Object
Returns the value of attribute project.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
-
#vcs ⇒ Object
Returns the value of attribute vcs.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(options) ⇒ DotenvToCI
constructor
A new instance of DotenvToCI.
- #load_from_env ⇒ Object
- #parse_envs(dotenv_paths) ⇒ Object
- #run! ⇒ Object
- #send_to_circleci(envs) ⇒ Object
- #verify_options! ⇒ Object
Constructor Details
#initialize(options) ⇒ DotenvToCI
Returns a new instance of DotenvToCI.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dotenv_to_ci.rb', line 15 def initialize() @dotenvs = [:dotenvs] @provider = [:provider] @token = [:token] @vcs = [:vcs] @username = [:username] @project = [:project] @verbose = [:verbose] load_from_env if verbose puts "Config: #{@token}" end end |
Instance Attribute Details
#dotenvs ⇒ Object
Returns the value of attribute dotenvs.
7 8 9 |
# File 'lib/dotenv_to_ci.rb', line 7 def dotenvs @dotenvs end |
#project ⇒ Object
Returns the value of attribute project.
12 13 14 |
# File 'lib/dotenv_to_ci.rb', line 12 def project @project end |
#provider ⇒ Object
Returns the value of attribute provider.
8 9 10 |
# File 'lib/dotenv_to_ci.rb', line 8 def provider @provider end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/dotenv_to_ci.rb', line 9 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/dotenv_to_ci.rb', line 11 def username @username end |
#vcs ⇒ Object
Returns the value of attribute vcs.
10 11 12 |
# File 'lib/dotenv_to_ci.rb', line 10 def vcs @vcs end |
#verbose ⇒ Object
Returns the value of attribute verbose.
13 14 15 |
# File 'lib/dotenv_to_ci.rb', line 13 def verbose @verbose end |
Instance Method Details
#load_from_env ⇒ Object
31 32 33 34 35 |
# File 'lib/dotenv_to_ci.rb', line 31 def load_from_env if @provider == "circleci" @token ||= ENV["CIRCLECI_TOKEN"] end end |
#parse_envs(dotenv_paths) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/dotenv_to_ci.rb', line 47 def parse_envs(dotenv_paths) envs = Dotenv.parse(dotenv_paths) if verbose puts "ENVS: #{envs}" end return envs end |
#run! ⇒ Object
37 38 39 40 41 |
# File 'lib/dotenv_to_ci.rb', line 37 def run! envs = parse_envs(@dotenvs) send_to_circleci(envs) end |
#send_to_circleci(envs) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dotenv_to_ci.rb', line 57 def send_to_circleci(envs) envs.each do |k,v| payload = { name: k, value: v } if verbose puts "Setting: #{payload}" end resp = RestClient::Request.execute( method: :post, url: "https://circleci.com/api/v1.1/project/#{vcs}/#{username}/#{project}/envvar?circle-token=#{@token}", payload: payload.to_json, headers: { 'Content-Type' => 'application/json' } ) end puts "Successfully added: #{envs.keys.join(', ')}" end |
#verify_options! ⇒ Object
43 44 45 |
# File 'lib/dotenv_to_ci.rb', line 43 def end |