Class: DotenvToCI::CircleCI

Inherits:
Object
  • Object
show all
Defined in:
lib/dotenv_to_ci/circleci.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @dotenvs = options[:dotenvs]
  @provider = options[:provider]
  @token = options[:token]
  @vcs = options[:vcs]
  @username = options[:username]
  @project = options[:project]
  @verbose = options[:verbose]

  load_from_env
end

Instance Attribute Details

#dotenvsObject

Returns the value of attribute dotenvs.



8
9
10
# File 'lib/dotenv_to_ci/circleci.rb', line 8

def dotenvs
  @dotenvs
end

#projectObject

Returns the value of attribute project.



13
14
15
# File 'lib/dotenv_to_ci/circleci.rb', line 13

def project
  @project
end

#providerObject

Returns the value of attribute provider.



9
10
11
# File 'lib/dotenv_to_ci/circleci.rb', line 9

def provider
  @provider
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/dotenv_to_ci/circleci.rb', line 10

def token
  @token
end

#usernameObject

Returns the value of attribute username.



12
13
14
# File 'lib/dotenv_to_ci/circleci.rb', line 12

def username
  @username
end

#vcsObject

Returns the value of attribute vcs.



11
12
13
# File 'lib/dotenv_to_ci/circleci.rb', line 11

def vcs
  @vcs
end

#verboseObject

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_envObject



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!
  verify_options!
  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 verify_options!
  
end