appetize-cli 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -1
- data/CHANGELOG.md +13 -1
- data/README.md +75 -17
- data/appetize.gemspec +5 -4
- data/exe/appetize +6 -6
- data/lib/appetize/api.rb +37 -0
- data/lib/appetize/ci/gitlab.rb +26 -0
- data/lib/appetize/cli.rb +26 -15
- data/lib/appetize/command.rb +11 -11
- data/lib/appetize/commands/delete.rb +7 -19
- data/lib/appetize/commands/update.rb +25 -0
- data/lib/appetize/commands/upload.rb +43 -25
- data/lib/appetize/templates/update/.gitkeep +1 -0
- data/lib/appetize/version.rb +1 -1
- data/lib/appetize.rb +0 -1
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cc8bacaba3e5f4e836d8e174d551bd32124a1ca8bfa4df92526492ac4904ae1
|
4
|
+
data.tar.gz: 7650c019adbc139aeac7beb5ee44e58f9163e340e26c7b6a43bf2f78204bd8b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 920e345be4a9c43c4cc12b853fbb0b354b2aebbd49fd6b368b6e220d344bac8d440446f7c62c39d34cd6509fb6337a49f01092f16118b99fc9388a098f4664f2
|
7
|
+
data.tar.gz: 49d8e0478a0ec95b035dc0737d758b3c798ec3cb8476a26e5b258f2ab882c452dda6e8237ee3876019facea3dedb81ee362edfbc88b0208aa1aedc88de8f8a1e
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
SuggestExtensions: false
|
4
|
+
NewCops: enable
|
3
5
|
|
4
6
|
Style/StringLiterals:
|
5
7
|
Enabled: true
|
@@ -11,3 +13,16 @@ Style/StringLiteralsInInterpolation:
|
|
11
13
|
|
12
14
|
Layout/LineLength:
|
13
15
|
Max: 120
|
16
|
+
|
17
|
+
Lint/MissingSuper:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Lint/UnusedMethodArgument:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/Documentation:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/BlockLength:
|
27
|
+
IgnoredMethods: ['describe', 'context']
|
28
|
+
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.1.
|
3
|
+
## [0.1.4] - 2021-09-11
|
4
|
+
|
5
|
+
- Upload command will detect & update existing Review Apps when running in GitLab CI
|
6
|
+
|
7
|
+
## [0.1.3] - 2021-09-09
|
8
|
+
|
9
|
+
- Upload command now returns full JSON response from Appetize
|
10
|
+
|
11
|
+
## [0.1.2] - 2021-09-02
|
12
|
+
|
13
|
+
- Adding specs, cleaning up gemspec, updated README
|
14
|
+
|
15
|
+
## [0.1.1] - 2021-08-30
|
4
16
|
|
5
17
|
- Initial release
|
data/README.md
CHANGED
@@ -1,43 +1,101 @@
|
|
1
|
-
# Appetize
|
1
|
+
# Appetize CLI
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
The Appetize CLI provides a command line interface to the [Appetize API](https://docs.appetize.io/api/overview).
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
Install this gem by executing:
|
8
|
+
|
9
|
+
$ gem install appetize-cli
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Currently there are two supported actions `upload` and `delete` - `help` and `version` commands are also supplied.
|
10
14
|
|
11
|
-
```
|
12
|
-
|
15
|
+
```
|
16
|
+
Commands:
|
17
|
+
appetize delete PUBLIC_KEY # Delete an app deploymment from Appetize
|
18
|
+
appetize help [COMMAND] # Describe available commands or one specific command
|
19
|
+
appetize upload PATH PLATFORM # Upload an APK/ZIP to Appetize
|
20
|
+
appetize version # appetize version
|
13
21
|
```
|
14
22
|
|
15
|
-
|
23
|
+
### Setup
|
16
24
|
|
17
|
-
|
25
|
+
All actions in this tool require an Appetize API token, which can be generated in your Appetize account. Once a token has been generated you must set it as the environment variable `APPETIZE_API_TOKEN`.
|
18
26
|
|
19
|
-
|
27
|
+
Example:
|
20
28
|
|
21
|
-
|
29
|
+
$ export APPETIZE_API_TOKEN=yourtoken
|
22
30
|
|
23
|
-
## Usage
|
24
31
|
|
25
|
-
|
32
|
+
### Upload
|
33
|
+
|
34
|
+
Upload an APK/ZIP to Appetize
|
35
|
+
|
36
|
+
```
|
37
|
+
Usage:
|
38
|
+
appetize upload PATH PLATFORM
|
39
|
+
```
|
40
|
+
|
41
|
+
`PATH` the path to the Apk or Zip file of the app you would like to deploy
|
42
|
+
|
43
|
+
`PLATFORM` either `ios` or `android`
|
44
|
+
|
45
|
+
Example:
|
46
|
+
|
47
|
+
$ appetize upload builds/app-debug.apk android
|
48
|
+
$ appetize upload builds/app.zip ios
|
49
|
+
|
50
|
+
### Update
|
51
|
+
|
52
|
+
Update an existing app in Appitize with a new APK/ZIP
|
53
|
+
|
54
|
+
```
|
55
|
+
Usage:
|
56
|
+
appetize update PATH PUBLIC_KEY
|
57
|
+
```
|
58
|
+
|
59
|
+
`PATH` the path to the Apk or Zip file of the app you would like to deploy
|
60
|
+
|
61
|
+
`PUBLIC_KEY` the public key provided by Appetize for the specific app deployment you'd like to update
|
62
|
+
|
63
|
+
Example:
|
64
|
+
|
65
|
+
$ appetize upload builds/app-debug.apk somepublickey
|
66
|
+
$ appetize upload builds/app.zip somepublickey
|
67
|
+
|
68
|
+
|
69
|
+
### Delete
|
70
|
+
|
71
|
+
Delete an app deploymment from Appetize
|
72
|
+
|
73
|
+
```
|
74
|
+
Usage:
|
75
|
+
appetize delete PUBLIC_KEY
|
76
|
+
```
|
77
|
+
|
78
|
+
`PUBLIC_KEY` the public key provided by Appetize for the specific app deployment you'd like to delete
|
79
|
+
|
80
|
+
Example:
|
81
|
+
|
82
|
+
$ appetize delete somepublickey
|
83
|
+
|
26
84
|
|
27
85
|
## Development
|
28
86
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
88
|
|
31
89
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
90
|
|
33
91
|
## Contributing
|
34
92
|
|
35
|
-
Bug reports and
|
93
|
+
Bug reports and merge requests are welcome on GitLab at https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli/-/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli/-/blob/master/CODE_OF_CONDUCT.md).
|
36
94
|
|
37
95
|
## Code of Conduct
|
38
96
|
|
39
|
-
Everyone interacting in the Appetize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
97
|
+
Everyone interacting in the Appetize CLI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli/-/blob/master/CODE_OF_CONDUCT.md).
|
40
98
|
|
41
99
|
## Copyright
|
42
100
|
|
43
|
-
Copyright (c) 2021
|
101
|
+
Copyright (c) 2021 GitLab, Inc. See [MIT License](LICENSE.txt) for further details.
|
data/appetize.gemspec
CHANGED
@@ -11,12 +11,12 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "A Command Line Interface to the Appetize.io API"
|
13
13
|
spec.description = "A Command Line Interface to the Appetize.io API"
|
14
|
-
spec.homepage = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize"
|
15
|
-
spec.required_ruby_version = ">= 2.
|
14
|
+
spec.homepage = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli"
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize"
|
19
|
-
spec.metadata["changelog_uri"] = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize/CHANGELOG.md"
|
18
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli"
|
19
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli/-/blob/master/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
33
33
|
spec.add_dependency "httparty"
|
34
|
+
spec.add_dependency "thor"
|
34
35
|
|
35
36
|
# For more information and examples about making a new gem, checkout our
|
36
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/exe/appetize
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
lib_path = File.expand_path(
|
5
|
-
|
6
|
-
require
|
4
|
+
lib_path = File.expand_path("../lib", __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
6
|
+
require "appetize/cli"
|
7
7
|
|
8
|
-
Signal.trap(
|
8
|
+
Signal.trap("INT") do
|
9
9
|
warn("\n#{caller.join("\n")}: interrupted")
|
10
10
|
exit(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
begin
|
14
14
|
Appetize::CLI.start
|
15
|
-
rescue Appetize::CLI::Error =>
|
16
|
-
puts "ERROR: #{
|
15
|
+
rescue Appetize::CLI::Error => e
|
16
|
+
puts "ERROR: #{e.message}"
|
17
17
|
exit 1
|
18
18
|
end
|
data/lib/appetize/api.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Appetize
|
6
|
+
class API
|
7
|
+
def initialize(token = nil, api_host = nil)
|
8
|
+
@token = token || ENV["APPETIZE_API_TOKEN"]
|
9
|
+
@api_host = api_host || "api.appetize.io"
|
10
|
+
|
11
|
+
raise "Appetize Token Missing" if @token.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(path, platform)
|
15
|
+
url = "https://#{@api_host}/v1/apps"
|
16
|
+
auth = { username: @token, password: "" }
|
17
|
+
body = { platform: platform, file: File.open(path) }
|
18
|
+
|
19
|
+
HTTParty.post(url, body: body, basic_auth: auth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(path, public_key)
|
23
|
+
url = "https://#{@api_host}/v1/apps/#{public_key}"
|
24
|
+
auth = { username: @token, password: "" }
|
25
|
+
body = { file: File.open(path) }
|
26
|
+
|
27
|
+
HTTParty.post(url, body: body, basic_auth: auth)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(public_key)
|
31
|
+
url = "https://#{@api_host}/v1/apps/#{public_key}"
|
32
|
+
auth = { username: @token, password: "" }
|
33
|
+
|
34
|
+
HTTParty.delete(url, basic_auth: auth)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Appetize
|
6
|
+
module CI
|
7
|
+
class GitLab
|
8
|
+
def initialize(project_id, ref_name, api_token, api_host = nil)
|
9
|
+
@project_id = project_id
|
10
|
+
@ref_name = ref_name
|
11
|
+
@api_token = api_token
|
12
|
+
@api_host = api_host || "https://gitlab.com/api/v4"
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch_artifact(job, artifact_name)
|
16
|
+
url = "#{@api_host}/projects/#{@project_id}/jobs/artifacts/#{@ref_name}/raw/#{artifact_name}?job=#{job}"
|
17
|
+
|
18
|
+
headers = {
|
19
|
+
"PRIVATE-TOKEN" => @api_token
|
20
|
+
}
|
21
|
+
|
22
|
+
HTTParty.get(url, headers: headers)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/appetize/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'httparty'
|
3
|
+
require "thor"
|
5
4
|
|
6
5
|
module Appetize
|
7
6
|
# Handle the application command line parsing
|
@@ -12,33 +11,45 @@ module Appetize
|
|
12
11
|
# Error raised by this runner
|
13
12
|
Error = Class.new(StandardError)
|
14
13
|
|
15
|
-
desc
|
14
|
+
desc "version", "appetize version"
|
16
15
|
def version
|
17
|
-
require_relative
|
16
|
+
require_relative "version"
|
18
17
|
puts "v#{Appetize::VERSION}"
|
19
18
|
end
|
20
|
-
map %w
|
19
|
+
map %w[--version -v] => :version
|
21
20
|
|
22
|
-
desc
|
23
|
-
method_option :help, aliases:
|
24
|
-
desc:
|
21
|
+
desc "update PATH PUBLIC_KEY", "Command description..."
|
22
|
+
method_option :help, aliases: "-h", type: :boolean,
|
23
|
+
desc: "Display usage information"
|
24
|
+
def update(path, public_key, token = nil, api_host = nil)
|
25
|
+
if options[:help]
|
26
|
+
invoke :help, ["update"]
|
27
|
+
else
|
28
|
+
require_relative "commands/update"
|
29
|
+
Appetize::Commands::Update.new(path, public_key, token, api_host, options).execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "upload PATH PLATFORM", "Upload an APK/ZIP to Appetize"
|
34
|
+
method_option :help, aliases: "-h", type: :boolean,
|
35
|
+
desc: "Display usage information"
|
25
36
|
def upload(path, platform, token = nil, api_host = nil)
|
26
37
|
if options[:help]
|
27
|
-
invoke :help, [
|
38
|
+
invoke :help, ["upload"]
|
28
39
|
else
|
29
|
-
require_relative
|
40
|
+
require_relative "commands/upload"
|
30
41
|
Appetize::Commands::Upload.new(path, platform, token, api_host, options).execute
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
|
-
desc
|
35
|
-
method_option :help, aliases:
|
36
|
-
desc:
|
45
|
+
desc "delete PUBLIC_KEY", "Delete an app deploymment from Appetize"
|
46
|
+
method_option :help, aliases: "-h", type: :boolean,
|
47
|
+
desc: "Display usage information"
|
37
48
|
def delete(public_key, token = nil, api_host = nil)
|
38
49
|
if options[:help]
|
39
|
-
invoke :help, [
|
50
|
+
invoke :help, ["delete"]
|
40
51
|
else
|
41
|
-
require_relative
|
52
|
+
require_relative "commands/delete"
|
42
53
|
Appetize::Commands::Delete.new(public_key, token, api_host, options).execute
|
43
54
|
end
|
44
55
|
end
|
data/lib/appetize/command.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "forwardable"
|
4
4
|
|
5
5
|
module Appetize
|
6
6
|
class Command
|
@@ -24,7 +24,7 @@ module Appetize
|
|
24
24
|
#
|
25
25
|
# @api public
|
26
26
|
def command(**options)
|
27
|
-
require
|
27
|
+
require "tty-command"
|
28
28
|
TTY::Command.new(options)
|
29
29
|
end
|
30
30
|
|
@@ -34,7 +34,7 @@ module Appetize
|
|
34
34
|
#
|
35
35
|
# @api public
|
36
36
|
def cursor
|
37
|
-
require
|
37
|
+
require "tty-cursor"
|
38
38
|
TTY::Cursor
|
39
39
|
end
|
40
40
|
|
@@ -44,7 +44,7 @@ module Appetize
|
|
44
44
|
#
|
45
45
|
# @api public
|
46
46
|
def editor
|
47
|
-
require
|
47
|
+
require "tty-editor"
|
48
48
|
TTY::Editor
|
49
49
|
end
|
50
50
|
|
@@ -54,7 +54,7 @@ module Appetize
|
|
54
54
|
#
|
55
55
|
# @api public
|
56
56
|
def generator
|
57
|
-
require
|
57
|
+
require "tty-file"
|
58
58
|
TTY::File
|
59
59
|
end
|
60
60
|
|
@@ -64,7 +64,7 @@ module Appetize
|
|
64
64
|
#
|
65
65
|
# @api public
|
66
66
|
def pager(**options)
|
67
|
-
require
|
67
|
+
require "tty-pager"
|
68
68
|
TTY::Pager.new(options)
|
69
69
|
end
|
70
70
|
|
@@ -74,7 +74,7 @@ module Appetize
|
|
74
74
|
#
|
75
75
|
# @api public
|
76
76
|
def platform
|
77
|
-
require
|
77
|
+
require "tty-platform"
|
78
78
|
TTY::Platform.new
|
79
79
|
end
|
80
80
|
|
@@ -84,7 +84,7 @@ module Appetize
|
|
84
84
|
#
|
85
85
|
# @api public
|
86
86
|
def prompt(**options)
|
87
|
-
require
|
87
|
+
require "tty-prompt"
|
88
88
|
TTY::Prompt.new(options)
|
89
89
|
end
|
90
90
|
|
@@ -94,7 +94,7 @@ module Appetize
|
|
94
94
|
#
|
95
95
|
# @api public
|
96
96
|
def screen
|
97
|
-
require
|
97
|
+
require "tty-screen"
|
98
98
|
TTY::Screen
|
99
99
|
end
|
100
100
|
|
@@ -104,7 +104,7 @@ module Appetize
|
|
104
104
|
#
|
105
105
|
# @api public
|
106
106
|
def which(*args)
|
107
|
-
require
|
107
|
+
require "tty-which"
|
108
108
|
TTY::Which.which(*args)
|
109
109
|
end
|
110
110
|
|
@@ -114,7 +114,7 @@ module Appetize
|
|
114
114
|
#
|
115
115
|
# @api public
|
116
116
|
def exec_exist?(*args)
|
117
|
-
require
|
117
|
+
require "tty-which"
|
118
118
|
TTY::Which.exist?(*args)
|
119
119
|
end
|
120
120
|
end
|
@@ -1,35 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../command"
|
4
|
+
require_relative "../api"
|
4
5
|
|
5
6
|
module Appetize
|
6
7
|
module Commands
|
7
8
|
class Delete < Appetize::Command
|
8
|
-
def initialize(public_key, token, api_host, options)
|
9
|
+
def initialize(public_key, token = nil, api_host = nil, options = {})
|
10
|
+
@api = Appetize::API.new(token, api_host)
|
9
11
|
@public_key = public_key
|
10
|
-
@token = token
|
11
|
-
@api_host = api_host
|
12
12
|
@options = options
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute(input: $stdin, output: $stdout)
|
16
|
-
|
17
|
-
api_host = @api_host || 'api.appetize.io'
|
16
|
+
response = @api.delete(@public_key)
|
18
17
|
|
19
|
-
|
20
|
-
auth = {
|
21
|
-
username: token,
|
22
|
-
password: ''
|
23
|
-
}
|
18
|
+
raise "Delete failed: #{response.code}" unless response.code == 200
|
24
19
|
|
25
|
-
response
|
26
|
-
|
27
|
-
if response.code == 200
|
28
|
-
output.puts response
|
29
|
-
else
|
30
|
-
message = "Delete failed: #{response.code}"
|
31
|
-
raise message
|
32
|
-
end
|
20
|
+
output.puts response.body
|
33
21
|
end
|
34
22
|
end
|
35
23
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../command"
|
4
|
+
require_relative "../api"
|
5
|
+
|
6
|
+
module Appetize
|
7
|
+
module Commands
|
8
|
+
class Update < Appetize::Command
|
9
|
+
def initialize(path, public_key, token, api_host, options)
|
10
|
+
@api = Appetize::API.new(token, api_host)
|
11
|
+
@path = path
|
12
|
+
@public_key = public_key
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(input: $stdin, output: $stdout)
|
17
|
+
response = @api.update(@path, @public_key)
|
18
|
+
|
19
|
+
raise "Update failed: #{response.code}" unless response.code == 200
|
20
|
+
|
21
|
+
output.puts response.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,40 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../command"
|
4
|
+
require_relative "../api"
|
5
|
+
require_relative "../ci/gitlab"
|
4
6
|
|
5
7
|
module Appetize
|
6
8
|
module Commands
|
7
9
|
class Upload < Appetize::Command
|
8
10
|
def initialize(path, platform, token, api_host, options)
|
9
|
-
@
|
11
|
+
@api = Appetize::API.new(token, api_host)
|
12
|
+
@path = path
|
10
13
|
@platform = platform
|
11
|
-
@
|
12
|
-
@api_host = api_host
|
13
|
-
@options = options
|
14
|
+
@options = options
|
14
15
|
end
|
15
16
|
|
16
17
|
def execute(input: $stdin, output: $stdout)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
response = HTTParty.post(url, body: body, basic_auth: auth)
|
31
|
-
|
32
|
-
if response.code == 200
|
33
|
-
output.puts response
|
34
|
-
else
|
35
|
-
message = "Upload failed: #{response.code}"
|
36
|
-
raise message
|
18
|
+
# If we are running in GitLab CI, check for an existing pipeline
|
19
|
+
# if a pipeline is found, fetch the public key and update the
|
20
|
+
# existing Appetize app
|
21
|
+
if Appetize::Commands::Upload.gitlab_ci?
|
22
|
+
artifact_response = fetch_gitlab_artifact
|
23
|
+
|
24
|
+
if artifact_response.code == 200
|
25
|
+
public_key = JSON.parse(artifact_response.body)["publicKey"]
|
26
|
+
|
27
|
+
response = @api.update(@path, public_key)
|
28
|
+
end
|
37
29
|
end
|
30
|
+
|
31
|
+
response = @api.create(@path, @platform) if public_key.nil?
|
32
|
+
|
33
|
+
raise "Upload failed: #{response.code}" unless response.code == 200
|
34
|
+
|
35
|
+
output.puts response.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.gitlab_ci?
|
39
|
+
ENV["GITLAB_CI"].to_s.downcase == "true"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def fetch_gitlab_artifact
|
45
|
+
gitlab_client = Appetize::CI::GitLab.new(
|
46
|
+
ENV["CI_PROJECT_ID"],
|
47
|
+
ENV["CI_COMMIT_REF_NAME"],
|
48
|
+
ENV["PRIVATE_TOKEN"],
|
49
|
+
ENV["CI_API_V4_URL"]
|
50
|
+
)
|
51
|
+
|
52
|
+
gitlab_client.fetch_artifact(
|
53
|
+
"startReview",
|
54
|
+
"appetize-information.json"
|
55
|
+
)
|
38
56
|
end
|
39
57
|
end
|
40
58
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/lib/appetize/version.rb
CHANGED
data/lib/appetize.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appetize-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: A Command Line Interface to the Appetize.io API
|
28
42
|
email:
|
29
43
|
- dfrey@gitlab.com
|
@@ -45,22 +59,26 @@ files:
|
|
45
59
|
- bin/setup
|
46
60
|
- exe/appetize
|
47
61
|
- lib/appetize.rb
|
62
|
+
- lib/appetize/api.rb
|
63
|
+
- lib/appetize/ci/gitlab.rb
|
48
64
|
- lib/appetize/cli.rb
|
49
65
|
- lib/appetize/command.rb
|
50
66
|
- lib/appetize/commands/.gitkeep
|
51
67
|
- lib/appetize/commands/delete.rb
|
68
|
+
- lib/appetize/commands/update.rb
|
52
69
|
- lib/appetize/commands/upload.rb
|
53
70
|
- lib/appetize/templates/.gitkeep
|
54
71
|
- lib/appetize/templates/delete/.gitkeep
|
72
|
+
- lib/appetize/templates/update/.gitkeep
|
55
73
|
- lib/appetize/templates/upload/.gitkeep
|
56
74
|
- lib/appetize/version.rb
|
57
|
-
homepage: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize
|
75
|
+
homepage: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli
|
58
76
|
licenses:
|
59
77
|
- MIT
|
60
78
|
metadata:
|
61
|
-
homepage_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize
|
62
|
-
source_code_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize
|
63
|
-
changelog_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize/CHANGELOG.md
|
79
|
+
homepage_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli
|
80
|
+
source_code_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli
|
81
|
+
changelog_uri: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli/-/blob/master/CHANGELOG.md
|
64
82
|
post_install_message:
|
65
83
|
rdoc_options: []
|
66
84
|
require_paths:
|
@@ -69,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
87
|
requirements:
|
70
88
|
- - ">="
|
71
89
|
- !ruby/object:Gem::Version
|
72
|
-
version: 2.
|
90
|
+
version: 2.5.0
|
73
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
92
|
requirements:
|
75
93
|
- - ">="
|