bump-cli 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00a05336bed7f3a4f81e5b59a102950d067acb25cfe6d4bbdb057c0bf83f2265
4
- data.tar.gz: 2f08c89b6ec3fbad5a85e1325309cf85da94cd7ded892ae06615c440c4623df5
3
+ metadata.gz: 165f19120b51a189b1f7428e00901fed5ea5b91bfb5f21bc2f9fe983adc3cc31
4
+ data.tar.gz: 724ec534aff1c7d264b185ca8c9d6bf46db552d8149d39fe2a2cf3c2185a341d
5
5
  SHA512:
6
- metadata.gz: c4686dc55a271061d849af7a4aa778c7e6f4a93a3c7bfd38667f0f72dab7dc137e050aa73fe3ba1062c838193accc0613bbc5452ab55e949bf85a99aa8258b60
7
- data.tar.gz: 34c42d4756f1dc1199af1a16d706298f07f8dc01723988322f58131d4312b8ffd624b25464152e294a999f870f9bea7499aa19f494b72f957fde9c098f41f857
6
+ metadata.gz: 5a5df45b5a14cb7e79063504ce1a5dc5e5342088840de2dcf6eca79928712b46115ed590765e4a516c497e461eb12cdeaa65ce052f217decfb5eb5e9075bfc7a
7
+ data.tar.gz: 3c3ab329ab7c5bd4d0bada3147cd4fdb8c61131fcc32efb3e980811e48bdecef868d1d99823e099b7b612b4b18755c1b7706cc71adb129e717dc2ddfa265e43c
@@ -3,7 +3,7 @@ jobs:
3
3
  build-latest: &common-build
4
4
  working_directory: ~/bump-cli
5
5
  docker:
6
- - image: circleci/ruby:2.5.0-node
6
+ - image: circleci/ruby:latest
7
7
  steps:
8
8
  - checkout
9
9
  - run:
@@ -29,20 +29,30 @@ jobs:
29
29
 
30
30
  - run:
31
31
  name: Run tests
32
- command: rake
32
+ command: bundle exec rspec
33
+ build-2-6:
34
+ <<: *common-build
35
+ docker:
36
+ - image: circleci/ruby:2.6
37
+ build-2-5:
38
+ <<: *common-build
39
+ docker:
40
+ - image: circleci/ruby:2.5
33
41
  build-2-4:
34
42
  <<: *common-build
35
43
  docker:
36
- - image: circleci/ruby:2.4.3-node
44
+ - image: circleci/ruby:2.4
37
45
  build-2-3:
38
46
  <<: *common-build
39
47
  docker:
40
- - image: circleci/ruby:2.3.6-node
48
+ - image: circleci/ruby:2.3
41
49
 
42
50
  workflows:
43
51
  version: 2
44
52
  build:
45
53
  jobs:
46
54
  - build-latest
55
+ - build-2-6
56
+ - build-2-5
47
57
  - build-2-4
48
58
  - build-2-3
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .byebug_history
2
+ .ruby-version
2
3
  /.bundle/
3
4
  /.yardoc
4
5
  /Gemfile.lock
data/README.md CHANGED
@@ -29,25 +29,31 @@ Bump tries to identify your file specification and format automatically. You can
29
29
  * `asyncapi/v2/json`
30
30
  * `asyncapi/v2/yaml`
31
31
 
32
- The doc `id` and `token` options used below can be found in your documentation settings page on https://bump.sh. Note that you can replace these options by environments variables: `--id` can be replaced by `BUMP_ID`, and `--token` can by replaced by `BUMP_TOKEN`. This is useful to keep your private token secret.
32
+ `doc` and `token` options used below can be found in your documentation settings page on https://bump.sh. Note that you can replace the token option by an environment variable, to keep it secret: `--token` can by replaced by `BUMP_TOKEN`.
33
33
 
34
34
  ### Preview
35
35
 
36
36
  You can preview your documentation by calling the `preview` command. A temporary preview will be created, with a unique URL. This preview will be available for 30 minutes. You don't need any credentials to use this command.
37
37
 
38
+ Preview a documentation:
39
+
38
40
  $ bundle exec bump preview path/to/your/file.yml
39
41
 
40
42
  ### Validate
41
43
 
42
- Validate your file against its specification.
44
+ Validate your file against its specification:
43
45
 
44
- $ bundle exec bump validate path/to/your/file.yml --id DOC_ID --token DOC_TOKEN
46
+ $ bundle exec bump validate path/to/your/file.yml --doc DOC_ID_OR_SLUG --token DOC_TOKEN
45
47
 
46
48
  ### Deploy
47
49
 
48
- Deploy the file as the current version of the documentation.
50
+ Deploy the file as the current version of the documentation:
51
+
52
+ $ bundle exec bump deploy path/to/your/file.yml --doc DOC_ID_OR_SLUG --token DOC_TOKEN
53
+
54
+ Automatically create a documentation inside a hub and deploy it:
49
55
 
50
- $ bundle exec bump deploy path/to/your/file.yml --id DOC_ID --token DOC_TOKEN
56
+ $ bundle exec bump deploy path/to/your/file.yml --auto-create --doc DOC_SLUG --hub HUB_ID_OR_SLUG --token HUB_TOKEN
51
57
 
52
58
  ## Development
53
59
 
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '>= 2.3'
28
28
 
29
- spec.add_dependency "hanami-cli", '~> 0'
29
+ spec.add_dependency "dry-cli", '~> 0'
30
30
  spec.add_dependency "http", '>= 3'
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1"
32
+ spec.add_development_dependency "bundler", ">= 1", "< 3"
33
33
  spec.add_development_dependency "byebug", "~> 11"
34
34
  spec.add_development_dependency "climate_control", '~> 0'
35
35
  spec.add_development_dependency "rake", "~> 13"
@@ -1,5 +1,5 @@
1
1
  require "bump/cli/version"
2
- require "hanami/cli"
2
+ require "dry/cli"
3
3
  require "http"
4
4
 
5
5
  module Bump
@@ -9,11 +9,11 @@ module Bump
9
9
  API_URL = ROOT_URL + API_PATH
10
10
 
11
11
  def call(*args)
12
- Hanami::CLI.new(Commands).call(*args)
12
+ Dry::CLI.new(Commands).call(*args)
13
13
  end
14
14
 
15
15
  module Commands
16
- extend Hanami::CLI::Registry
16
+ extend Dry::CLI::Registry
17
17
  end
18
18
  end
19
19
  end
@@ -1,9 +1,10 @@
1
- require 'open-uri'
1
+ require 'bump/cli/definition'
2
+ require 'bump/cli/uuid'
2
3
 
3
4
  module Bump
4
5
  class CLI
5
6
  module Commands
6
- class Base < Hanami::CLI::Command
7
+ class Base < Dry::CLI::Command
7
8
  USER_AGENT = "bump-cli/#{VERSION}".freeze
8
9
 
9
10
  private
@@ -14,11 +15,64 @@ module Bump
14
15
  .post(url, body: body)
15
16
  end
16
17
 
17
- def body(file, specification)
18
- {
19
- definition: open(file).read,
20
- specification: specification
21
- }
18
+ def body(file, **options)
19
+ deprecation_warning(options)
20
+
21
+ compact(
22
+ {
23
+ definition: prepare_file(file, options),
24
+ specification: options[:specification],
25
+ validation: options[:validation],
26
+ auto_create_documentation: options[:'auto-create']
27
+ }.merge(documentation_or_hub(options))
28
+ )
29
+ end
30
+
31
+ def prepare_file(file, options)
32
+ Definition.new(file, import_external_references: options[:'import-external-references']).prepare
33
+ end
34
+
35
+ def deprecation_warning(options)
36
+ if present?(options[:id])
37
+ puts "[DEPRECATION WARNING] --id option is deprecated. Please use --doc instead."
38
+ end
39
+ end
40
+
41
+ def present?(string)
42
+ !string.nil? && string != ''
43
+ end
44
+
45
+ def compact(hash)
46
+ hash.delete_if { |key, value| value.nil? }
47
+ end
48
+
49
+ def documentation_or_hub(options)
50
+ result = {}
51
+
52
+ result[:documentation_id] = options[:id]
53
+ result[:documentation_id] = options[:doc] if documentation_uuid?(options)
54
+ result[:documentation_slug] = options[:doc] if documentation_slug?(options)
55
+ result[:documentation_name] = options[:'doc-name']
56
+ result[:hub_id] = options[:hub] if hub_uuid?(options)
57
+ result[:hub_slug] = options[:hub] if hub_slug?(options)
58
+
59
+ compact(result)
60
+ end
61
+
62
+ def documentation_uuid?(options)
63
+ Bump::CLI::UUID.valid?(options[:doc])
64
+ end
65
+
66
+ def documentation_slug?(options)
67
+ !options[:doc].nil? && !documentation_uuid?(options)
68
+ end
69
+
70
+ def hub_uuid?(options)
71
+ Bump::CLI::UUID.valid?(options[:hub])
72
+ end
73
+
74
+ def hub_slug?(options)
75
+ !options[:hub].nil? && !hub_uuid?(options)
22
76
  end
23
77
 
24
78
  def with_errors_rescued
@@ -6,22 +6,28 @@ module Bump
6
6
  class Deploy < Base
7
7
  desc "Create a new version"
8
8
  argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
- option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
- option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
9
+ option :id, default: ENV.fetch("BUMP_ID", ""), desc: "[DEPRECATED] Documentation id. Use `documentation` option instead"
10
+ option :doc, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation id or slug"
11
+ option :'doc-name', desc: "Documentation name. Used with --auto-create flag."
12
+ option :hub, default: ENV.fetch("BUMP_HUB_ID", ""), desc: "Hub id or slug"
13
+ option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation or Hub token"
11
14
  option :specification, desc: "Specification of the definition"
15
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
16
+ option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
17
+ option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
12
18
 
13
- def call(file:, id:, token:, specification: nil)
19
+ def call(file:, **options)
14
20
  with_errors_rescued do
15
21
  response = post(
16
- url: API_URL + "/docs/#{id}/versions",
17
- body: body(file, specification).to_json,
18
- token: token
22
+ url: API_URL + "/versions",
23
+ body: body(file, **options).to_json,
24
+ token: options[:token]
19
25
  )
20
26
 
21
27
  if response.code == 201
22
- puts "New version has been successfully deployed."
28
+ puts "The new version is currently being processed."
23
29
  elsif response.code == 204
24
- puts "Version was already deployed."
30
+ puts "This version has already been deployed."
25
31
  else
26
32
  display_error(response)
27
33
  end
@@ -5,12 +5,14 @@ module Bump
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. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
7
7
  option :specification, desc: "Specification of the definition"
8
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
9
+ option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
8
10
 
9
- def call(file:, specification: nil)
11
+ def call(file:, **options)
10
12
  with_errors_rescued do
11
13
  response = post(
12
14
  url: API_URL + "/previews",
13
- body: body(file, specification).to_json
15
+ body: body(file, **options).to_json
14
16
  )
15
17
 
16
18
  if response.code == 201
@@ -6,16 +6,22 @@ module Bump
6
6
  class Validate < Base
7
7
  desc "Validate a given file against its schema definition"
8
8
  argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
- option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
- option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
9
+ option :id, default: ENV.fetch("BUMP_ID", ""), desc: "[DEPRECATED] Documentation id. Use `documentation` option instead"
10
+ option :doc, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id or slug"
11
+ option :'doc-name', desc: "Documentation name. Used with --auto-create flag."
12
+ option :hub, desc: "Hub id or slug"
13
+ option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation or Hub token"
11
14
  option :specification, desc: "Specification of the definition"
15
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
16
+ option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
17
+ option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
12
18
 
13
- def call(file:, id:, token:, specification: nil)
19
+ def call(file:, **options)
14
20
  with_errors_rescued do
15
21
  response = post(
16
- url: API_URL + "/docs/#{id}/validations",
17
- body: body(file, specification).to_json,
18
- token: token
22
+ url: API_URL + "/validations",
23
+ body: body(file, **options).to_json,
24
+ token: options[:token]
19
25
  )
20
26
 
21
27
  if response.code == 200
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+ require 'bump/cli/parser'
3
+ require 'bump/cli/references'
4
+
5
+ module Bump
6
+ class CLI
7
+ class Definition
8
+ def initialize(path, import_external_references: false)
9
+ @path = path
10
+ @import_external_references = import_external_references
11
+ end
12
+
13
+ def prepare
14
+ if !import_external_references
15
+ read_file
16
+ else
17
+ parse_file_and_import_external_references
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :path, :import_external_references
24
+
25
+ def read_file
26
+ open(path).read
27
+ end
28
+
29
+ def parse_file_and_import_external_references
30
+ original_format, definition = parser.load(read_file)
31
+
32
+ references = References.new(definition, base_path: path)
33
+ references.import!
34
+
35
+ parser.dump(references.definition, original_format)
36
+ end
37
+
38
+ def parser
39
+ @parser ||= Parser.new
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
4
+ module Bump
5
+ class CLI
6
+ class Parser
7
+ def load(content)
8
+ [:json, ::JSON.parse(content)]
9
+ rescue ::JSON::ParserError => e
10
+ begin
11
+ [:yaml, ::YAML.safe_load(content, [Date, Time])]
12
+ rescue ::Psych::SyntaxError
13
+ [:text, content]
14
+ end
15
+ end
16
+
17
+ def dump(definition, format)
18
+ if format == :yaml
19
+ ::YAML.dump(definition)
20
+ else
21
+ ::JSON.dump(definition)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,92 @@
1
+ require 'open-uri'
2
+ require 'pathname'
3
+
4
+ module Bump
5
+ class CLI
6
+ class References
7
+ attr_reader :definition
8
+
9
+ def initialize(definition, base_path: '')
10
+ @definition = definition
11
+ @base_path = cleanup(base_path)
12
+ @processed = false
13
+ @external_references = {}
14
+ end
15
+
16
+ def import!
17
+ if !processed
18
+ @definition = traverse_and_replace_external_references(definition)
19
+ import_references
20
+ @processed = true
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :base_path, :processed, :external_references
27
+
28
+ def traverse_and_replace_external_references(current)
29
+ current.each do |key, value|
30
+ if key == '$ref'
31
+ current[key] = replace_external_reference(value)
32
+ elsif value.is_a?(Hash)
33
+ traverse_and_replace_external_references(value)
34
+ elsif value.is_a?(Array)
35
+ value.each do |array_value|
36
+ traverse_and_replace_external_references(array_value)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def replace_external_reference(reference)
43
+ if external?(reference)
44
+ if external_references[reference].nil?
45
+ @external_references[reference] = "#{external_references.count + 1}"
46
+ end
47
+
48
+ subpath = reference[/#(.*)$/, 1]
49
+ "#/components/x-imported/#{external_references[reference]}#{ '/' + subpath if !subpath.nil? }"
50
+ else
51
+ reference
52
+ end
53
+ end
54
+
55
+ def import_references
56
+ if external_references.count > 0
57
+ @definition['components'] = {} if @definition['components'].nil?
58
+ @definition['components']['x-imported'] = {} if @definition['components']['x-imported'].nil?
59
+
60
+ external_references.each do |key, value|
61
+ _, @definition['components']['x-imported'][value.to_s] = Parser.new.load(open(prepare_path(key)).read)
62
+ end
63
+ end
64
+ end
65
+
66
+ def prepare_path(key)
67
+ key = key.sub(/#.*/, '')
68
+ if url?(key) || absolute_path?(key)
69
+ key
70
+ else
71
+ base_path + key
72
+ end
73
+ end
74
+
75
+ def external?(reference)
76
+ !reference.start_with?('#')
77
+ end
78
+
79
+ def url?(path)
80
+ path.start_with?('http')
81
+ end
82
+
83
+ def absolute_path?(path)
84
+ path.start_with?('/')
85
+ end
86
+
87
+ def cleanup(path)
88
+ Pathname.new(path).dirname.to_s + Pathname::SEPARATOR_LIST
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,11 @@
1
+ module Bump
2
+ class CLI
3
+ class UUID
4
+ REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
5
+
6
+ def self.valid?(string)
7
+ string.to_s =~ REGEXP
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Bump
2
2
  class CLI
3
- VERSION = "0.4.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehdi Lahmam
8
8
  - Sébastien Charrier
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-10-31 00:00:00.000000000 Z
12
+ date: 2020-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: hanami-cli
15
+ name: dry-cli
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
@@ -43,16 +43,22 @@ dependencies:
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '3'
49
52
  type: :development
50
53
  prerelease: false
51
54
  version_requirements: !ruby/object:Gem::Requirement
52
55
  requirements:
53
- - - "~>"
56
+ - - ">="
54
57
  - !ruby/object:Gem::Version
55
58
  version: '1'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: byebug
58
64
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +155,10 @@ files:
149
155
  - lib/bump/cli/commands/deploy.rb
150
156
  - lib/bump/cli/commands/preview.rb
151
157
  - lib/bump/cli/commands/validate.rb
158
+ - lib/bump/cli/definition.rb
159
+ - lib/bump/cli/parser.rb
160
+ - lib/bump/cli/references.rb
161
+ - lib/bump/cli/uuid.rb
152
162
  - lib/bump/cli/version.rb
153
163
  homepage: https://bump.sh
154
164
  licenses:
@@ -156,7 +166,7 @@ licenses:
156
166
  metadata:
157
167
  allowed_push_host: https://rubygems.org
158
168
  source_code_uri: https://github.com/bump-sh/bump-cli
159
- post_install_message:
169
+ post_install_message:
160
170
  rdoc_options: []
161
171
  require_paths:
162
172
  - lib
@@ -171,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
181
  - !ruby/object:Gem::Version
172
182
  version: '0'
173
183
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.7.4
176
- signing_key:
184
+ rubygems_version: 3.1.2
185
+ signing_key:
177
186
  specification_version: 4
178
187
  summary: Bump.sh CLI
179
188
  test_files: []