Class: Appetize::Commands::Upload

Inherits:
Appetize::Command show all
Defined in:
lib/appetize/commands/upload.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Appetize::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(path, platform, token, api_host, options) ⇒ Upload

Returns a new instance of Upload.


10
11
12
13
14
15
# File 'lib/appetize/commands/upload.rb', line 10

def initialize(path, platform, token, api_host, options)
  @api      = Appetize::API.new(token, api_host)
  @path     = path
  @platform = platform
  @options  = options
end

Class Method Details

.gitlab_ci?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/appetize/commands/upload.rb', line 38

def self.gitlab_ci?
  ENV["GITLAB_CI"].to_s.downcase == "true"
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appetize/commands/upload.rb', line 17

def execute(input: $stdin, output: $stdout)
  # If we are running in GitLab CI, check for an existing pipeline
  # if a pipeline is found, fetch the public key and update the
  # existing Appetize app
  if Appetize::Commands::Upload.gitlab_ci?
    artifact_response = fetch_gitlab_artifact

    if artifact_response.code == 200
      public_key = JSON.parse(artifact_response.body)["publicKey"]

      response = @api.update(@path, public_key)
    end
  end

  response = @api.create(@path, @platform) if public_key.nil?

  raise "Upload failed: #{response.code}" unless response.code == 200

  output.puts response.body
end