bump-cli 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bump-cli.gemspec +1 -0
- data/lib/bump/cli.rb +1 -1
- data/lib/bump/cli/commands/base.rb +39 -13
- data/lib/bump/cli/commands/deploy.rb +7 -5
- data/lib/bump/cli/commands/preview.rb +6 -5
- data/lib/bump/cli/commands/validate.rb +7 -5
- data/lib/bump/cli/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc466d8c09963a1ac25e48d63016b6604750bb6dd5047e58c8dbb7735b104187
|
4
|
+
data.tar.gz: 8e86094c69c571e5e3b37dc89f2c0634006545651c0798e5094bc93ec303dc88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afc11a8d8e2c15a9e6eb252cd059f0c9076b4e443bd53ea385817b9c1f45768b6f93bdc0e50f3756f3c1b1e049fe265a289210396a4ca3cc0772d1bc0024f47
|
7
|
+
data.tar.gz: 80df03f014b02a00cde98e21c0a38b832273245d7bbe7cba718c5dab46881f1d9302a2a233e1960479c755a932bb9cf7d0b5004c01bc23de753c6324d3fec91b
|
data/.gitignore
CHANGED
data/bump-cli.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency "http", '~> 3'
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.15"
|
33
|
+
spec.add_development_dependency "byebug", "~> 9"
|
33
34
|
spec.add_development_dependency "climate_control", '~> 0'
|
34
35
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
36
|
spec.add_development_dependency "rspec", "~> 3"
|
data/lib/bump/cli.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
require 'open-uri'
|
2
|
+
require 'byebug'
|
2
3
|
|
3
4
|
module Bump
|
4
5
|
class CLI
|
5
6
|
module Commands
|
6
7
|
class Base < Hanami::CLI::Command
|
8
|
+
USER_AGENT = "bump-cli/#{VERSION}".freeze
|
9
|
+
|
7
10
|
private
|
8
11
|
|
12
|
+
def post(url:, body:, token: nil)
|
13
|
+
HTTP
|
14
|
+
.headers(headers(token: token))
|
15
|
+
.post(url, body: body)
|
16
|
+
end
|
17
|
+
|
9
18
|
def body(file, specification)
|
10
19
|
{
|
11
20
|
definition: open(file).read,
|
@@ -20,22 +29,22 @@ module Bump
|
|
20
29
|
end
|
21
30
|
|
22
31
|
def headers(token: '')
|
32
|
+
headers = {
|
33
|
+
'Content-Type' => 'application/json',
|
34
|
+
'User-Agent' => USER_AGENT
|
35
|
+
}
|
36
|
+
|
23
37
|
if token
|
24
|
-
{
|
25
|
-
"Content-Type" => "application/json",
|
26
|
-
"Authorization" => "Basic #{Base64.strict_encode64(token + ':')}"
|
27
|
-
}
|
28
|
-
else
|
29
|
-
{
|
30
|
-
"Content-Type" => "application/json"
|
31
|
-
}
|
38
|
+
headers['Authorization'] = "Basic #{Base64.strict_encode64(token + ':')}"
|
32
39
|
end
|
40
|
+
|
41
|
+
headers
|
33
42
|
end
|
34
43
|
|
35
44
|
def display_error(response)
|
36
45
|
if response.code == 422
|
37
46
|
body = JSON.parse(response.body)
|
38
|
-
|
47
|
+
display_validation_errors(body)
|
39
48
|
elsif response.code == 401
|
40
49
|
abort "Invalid credentials (status: 401)"
|
41
50
|
else
|
@@ -46,13 +55,30 @@ module Bump
|
|
46
55
|
abort "Unknown error (status: #{response.code})"
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
def display_validation_errors(body)
|
59
|
+
errors = body.dig('errors') || []
|
60
|
+
|
61
|
+
$stderr.puts "Invalid request:"
|
62
|
+
errors.each do |attribute, messages|
|
63
|
+
display_attribute_errors(attribute, messages)
|
53
64
|
end
|
65
|
+
|
54
66
|
abort
|
55
67
|
end
|
68
|
+
|
69
|
+
def display_attribute_errors(attribute, messages)
|
70
|
+
case
|
71
|
+
when messages.is_a?(String)
|
72
|
+
$stderr.puts "- #{attribute}: #{messages}"
|
73
|
+
when messages.is_a?(Array) && messages.count == 1
|
74
|
+
$stderr.puts "- #{attribute}: #{messages[0]}"
|
75
|
+
when messages.is_a?(Array)
|
76
|
+
$stderr.puts "- #{attribute}:"
|
77
|
+
messages.each do |message|
|
78
|
+
$stderr.puts " #{message}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
56
82
|
end
|
57
83
|
end
|
58
84
|
end
|
@@ -8,13 +8,15 @@ module Bump
|
|
8
8
|
argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
|
9
9
|
option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
|
10
10
|
option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
|
11
|
-
option :specification,
|
11
|
+
option :specification, desc: "Specification of the definition"
|
12
12
|
|
13
|
-
def call(file:,
|
13
|
+
def call(file:, id:, token:, specification: nil)
|
14
14
|
with_errors_rescued do
|
15
|
-
response =
|
16
|
-
|
17
|
-
|
15
|
+
response = post(
|
16
|
+
url: API_URL + "/docs/#{id}/versions",
|
17
|
+
body: body(file, specification).to_json,
|
18
|
+
token: token
|
19
|
+
)
|
18
20
|
|
19
21
|
if response.code == 201
|
20
22
|
puts "New version has been successfully deployed."
|
@@ -4,13 +4,14 @@ module Bump
|
|
4
4
|
class Preview < Base
|
5
5
|
desc "Create a documentation preview for the given file"
|
6
6
|
argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
|
7
|
-
option :specification,
|
7
|
+
option :specification, desc: "Specification of the definition"
|
8
8
|
|
9
|
-
def call(file:, specification:)
|
9
|
+
def call(file:, specification: nil)
|
10
10
|
with_errors_rescued do
|
11
|
-
response =
|
12
|
-
|
13
|
-
|
11
|
+
response = post(
|
12
|
+
url: API_URL + "/previews",
|
13
|
+
body: body(file, specification).to_json
|
14
|
+
)
|
14
15
|
|
15
16
|
if response.code == 201
|
16
17
|
body = JSON.parse(response.body)
|
@@ -8,13 +8,15 @@ module Bump
|
|
8
8
|
argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
|
9
9
|
option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
|
10
10
|
option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
|
11
|
-
option :specification,
|
11
|
+
option :specification, desc: "Specification of the definition"
|
12
12
|
|
13
|
-
def call(file:,
|
13
|
+
def call(file:, id:, token:, specification: nil)
|
14
14
|
with_errors_rescued do
|
15
|
-
response =
|
16
|
-
|
17
|
-
|
15
|
+
response = post(
|
16
|
+
url: API_URL + "/docs/#{id}/validations",
|
17
|
+
body: body(file, specification).to_json,
|
18
|
+
token: token
|
19
|
+
)
|
18
20
|
|
19
21
|
if response.code == 200
|
20
22
|
puts "Definition is valid."
|
data/lib/bump/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bump-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehdi Lahmam
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hanami-cli
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '1.15'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: byebug
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '9'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '9'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: climate_control
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|