Class: DotenvToCI::CircleCI
- Inherits:
-
Object
- Object
- DotenvToCI::CircleCI
- Defined in:
- lib/dotenv_to_ci/circleci.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) ⇒ CircleCI
constructor
A new instance of CircleCI.
- #load_from_env ⇒ Object
- #parse_envs(dotenv_paths) ⇒ Object
- #run! ⇒ Object
- #send_to_circleci(envs) ⇒ Object
- #verify_options! ⇒ Object
Constructor Details
#initialize(options) ⇒ CircleCI
Returns a new instance of CircleCI.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dotenv_to_ci/circleci.rb', line 16 def initialize() @dotenvs = [:dotenvs] @provider = [:provider] @token = [:token] @vcs = [:vcs] @username = [:username] @project = [:project] @verbose = [:verbose] load_from_env end |
Instance Attribute Details
#dotenvs ⇒ Object
Returns the value of attribute dotenvs.
8 9 10 |
# File 'lib/dotenv_to_ci/circleci.rb', line 8 def dotenvs @dotenvs end |
#project ⇒ Object
Returns the value of attribute project.
13 14 15 |
# File 'lib/dotenv_to_ci/circleci.rb', line 13 def project @project end |
#provider ⇒ Object
Returns the value of attribute provider.
9 10 11 |
# File 'lib/dotenv_to_ci/circleci.rb', line 9 def provider @provider end |
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/dotenv_to_ci/circleci.rb', line 10 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/dotenv_to_ci/circleci.rb', line 12 def username @username end |
#vcs ⇒ Object
Returns the value of attribute vcs.
11 12 13 |
# File 'lib/dotenv_to_ci/circleci.rb', line 11 def vcs @vcs end |
#verbose ⇒ Object
Returns the value of attribute verbose.
14 15 16 |
# File 'lib/dotenv_to_ci/circleci.rb', line 14 def verbose @verbose end |
Instance Method Details
#load_from_env ⇒ Object
28 29 30 31 32 |
# File 'lib/dotenv_to_ci/circleci.rb', line 28 def load_from_env if @provider == "circleci" @token ||= ENV["CIRCLECI_TOKEN"] end end |
#parse_envs(dotenv_paths) ⇒ Object
44 45 46 |
# File 'lib/dotenv_to_ci/circleci.rb', line 44 def parse_envs(dotenv_paths) return Dotenv.parse(dotenv_paths) end |
#run! ⇒ Object
34 35 36 37 38 |
# File 'lib/dotenv_to_ci/circleci.rb', line 34 def run! envs = parse_envs(@dotenvs) send_to_circleci(envs) end |
#send_to_circleci(envs) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dotenv_to_ci/circleci.rb', line 48 def send_to_circleci(envs) envs.each do |k,v| payload = { name: k, value: v } if $verbose puts "Setting key=#{k} value=#{v}" 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
40 41 42 |
# File 'lib/dotenv_to_ci/circleci.rb', line 40 def end |