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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5169670a252b09da084e26e8d2b8278edd15d9e904f123983f68649c5ead88f
4
- data.tar.gz: 186066a217405dbdef02f5f95c05954925220b400aaa1b2ba8320366b5d807d3
3
+ metadata.gz: cc466d8c09963a1ac25e48d63016b6604750bb6dd5047e58c8dbb7735b104187
4
+ data.tar.gz: 8e86094c69c571e5e3b37dc89f2c0634006545651c0798e5094bc93ec303dc88
5
5
  SHA512:
6
- metadata.gz: 358db0967d78738d45711ad7628c2b407f565b3032e526704e7919c47916774686c02dd093d857a6d3ffc8ed2829905fdb739b7a50627f0f04f37a95fe5446ec
7
- data.tar.gz: aedba4f9f17a31bdbf2cfb85a6d297fe7b4ecb9924559c815e74262fb08aea0a07766d869b9ab3d54a0eec6b2f85f431aeec58822c20ce89ffad52c3e40abc0d
6
+ metadata.gz: 0afc11a8d8e2c15a9e6eb252cd059f0c9076b4e443bd53ea385817b9c1f45768b6f93bdc0e50f3756f3c1b1e049fe265a289210396a4ca3cc0772d1bc0024f47
7
+ data.tar.gz: 80df03f014b02a00cde98e21c0a38b832273245d7bbe7cba718c5dab46881f1d9302a2a233e1960479c755a932bb9cf7d0b5004c01bc23de753c6324d3fec91b
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .byebug_history
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -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"
@@ -4,7 +4,7 @@ require "http"
4
4
 
5
5
  module Bump
6
6
  class CLI
7
- ROOT_URL = "https://bump.sh".freeze
7
+ ROOT_URL = "https://bump-staging.herokuapp.com".freeze
8
8
  API_PATH = "/api/v1".freeze
9
9
  API_URL = ROOT_URL + API_PATH
10
10
 
@@ -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
- display_invalid_definition(body)
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 display_invalid_definition(body)
50
- puts "Definition is not valid:"
51
- body["errors"]["raw_definition"].each do |error|
52
- puts "> #{error}"
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, default: 'openapi/v2/yaml', desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
12
 
13
- def call(file:, specification:, id:, token:)
13
+ def call(file:, id:, token:, specification: nil)
14
14
  with_errors_rescued do
15
- response = HTTP
16
- .headers(headers(token: token))
17
- .post(API_URL + "/docs/#{id}/versions", body: body(file, specification).to_json)
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, default: 'openapi/v2/yaml', desc: "Specification of the definition"
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 = HTTP
12
- .headers(headers)
13
- .post(API_URL + "/previews", body: body(file, specification).to_json)
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, default: 'openapi/v2/yaml', desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
12
 
13
- def call(file:, specification:, id:, token:)
13
+ def call(file:, id:, token:, specification: nil)
14
14
  with_errors_rescued do
15
- response = HTTP
16
- .headers(headers(token: token))
17
- .post(API_URL + "/docs/#{id}/validations", body: body(file, specification).to_json)
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."
@@ -1,5 +1,5 @@
1
1
  module Bump
2
2
  class CLI
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
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.2.1
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-08-16 00:00:00.000000000 Z
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