pact_broker-client 1.60.0 → 1.61.0

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: 8cd60c123fbe4481515d784d73f97296280109f50252c150c1c0c083813cb34b
4
- data.tar.gz: 3b8371bd71d74a2b9ada1b3ba2d54a24f5ae6349ce2c6a44075e72546f6dbf6e
3
+ metadata.gz: e9d724c27e98c131d955d07160fc82b162fd16b53b8f2df9e7b8f43a43967876
4
+ data.tar.gz: f1128e525285066f9ed81641368f07dd64a806de10d8d501dbf626d411fc2a2a
5
5
  SHA512:
6
- metadata.gz: 828e7e3d9eae551b586bff597b7229c5174ab4000fda79cab8567163b7b3c7443c535c35f504f530dc611bee0708240e27a8756bd394f5b9780047b3f8fc2391
7
- data.tar.gz: 9d64d148a588d7aa240decdab057c2352409944036d35f6d7ff67a18f673107b7324d383a96bdaaa67b14e837556d04b87f91b5126c77e8103e4a3cffd153ff2
6
+ metadata.gz: 38f5ff3fe01ff74f462744e9cc6363eff0a62189a8561f524c24042bfd3ea1b9eea2249ed2d3508201d833bf7e08c8c69f9ad56eb8d14777cda33e3092ae4d4b
7
+ data.tar.gz: e0b5e788bfb8053429ba735c135c175b4ac5048d2a382c12dd4c424fc9cbdd4b6370167c57791a6978e684e9a1a778197530f05d331541d8bffe18bea4e683fa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ <a name="v1.61.0"></a>
2
+ ### v1.61.0 (2022-05-06)
3
+
4
+ #### Features
5
+
6
+ * **create-or-update-version**
7
+ * support creating or updating a pacticipant version with a branch and/or tags ([e38e728](/../../commit/e38e728))
8
+
1
9
  <a name="v1.60.0"></a>
2
10
  ### v1.60.0 (2022-05-03)
3
11
 
data/README.md CHANGED
@@ -482,8 +482,8 @@ Description:
482
482
  support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see
483
483
  https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/
484
484
 
485
- Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The
486
- "test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
485
+ Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The "test"
486
+ and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
487
487
  https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.
488
488
 
489
489
  $ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
@@ -493,8 +493,8 @@ Description:
493
493
 
494
494
  $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat
495
495
 
496
- Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy
497
- with the versions of each integrated application that are already in that environment.
496
+ Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy with
497
+ the versions of each integrated application that are already in that environment.
498
498
 
499
499
  $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT
500
500
 
@@ -502,8 +502,8 @@ Description:
502
502
 
503
503
  $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test
504
504
 
505
- Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the
506
- latest version from the main branch of another application" it functions as a "can I merge" check.
505
+ Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the latest version
506
+ from the main branch of another application" it functions as a "can I merge" check.
507
507
 
508
508
  $ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \ --pacticipant Bar --latest main
509
509
 
@@ -650,8 +650,8 @@ Options:
650
650
  ```
651
651
 
652
652
  Description:
653
- Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the
654
- consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
653
+ Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer,
654
+ provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
655
655
 
656
656
  Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
657
657
  option. Please use the --broker-username or environment variable for the Pact Broker username.
@@ -715,9 +715,9 @@ Options:
715
715
  ```
716
716
 
717
717
  Description:
718
- Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and
719
- add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid
720
- must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
718
+ Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the
719
+ consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must
720
+ also be provided. You can generate a valid UUID by using the `generate-uuid` command.
721
721
 
722
722
  Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
723
723
  option. Please use the --broker-username or environment variable for the Pact Broker username.
@@ -814,6 +814,39 @@ Options:
814
814
 
815
815
  Describes a pacticipant version. If no version or tag is specified, the latest version is described.
816
816
 
817
+ #### create-or-update-version
818
+
819
+ ```
820
+ Usage:
821
+ pact-broker create-or-update-version -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL -e, --version=VERSION
822
+
823
+ Options:
824
+ -a, --pacticipant=PACTICIPANT
825
+ # The pacticipant name
826
+ -e, --version=VERSION
827
+ # The pacticipant version number
828
+ [--branch=BRANCH]
829
+ # The repository branch name
830
+ -t, [--tag=TAG]
831
+ # Tag name for pacticipant version. Can be specified multiple
832
+ times.
833
+ -b, --broker-base-url=BROKER_BASE_URL
834
+ # The base URL of the Pact Broker
835
+ -u, [--broker-username=BROKER_USERNAME]
836
+ # Pact Broker basic auth username
837
+ -p, [--broker-password=BROKER_PASSWORD]
838
+ # Pact Broker basic auth password
839
+ -k, [--broker-token=BROKER_TOKEN]
840
+ # Pact Broker bearer token
841
+ -v, [--verbose], [--no-verbose]
842
+ # Verbose output. Default: false
843
+ -o, [--output=OUTPUT]
844
+ # json or text
845
+ # Default: text
846
+ ```
847
+
848
+ Create or update pacticipant version by version number
849
+
817
850
  ### Miscellaneous
818
851
 
819
852
  #### generate-uuid
@@ -1,228 +1,44 @@
1
- require 'pact_broker/client/cli/custom_thor'
2
- require 'pact_broker/client/hash_refinements'
3
- require 'thor/error'
4
- require 'pact_broker/client/cli/environment_commands'
5
- require 'pact_broker/client/cli/deployment_commands'
6
- require 'pact_broker/client/cli/pacticipant_commands'
7
- require 'pact_broker/client/cli/webhook_commands'
1
+ require "pact_broker/client/cli/custom_thor"
2
+ require "pact_broker/client/hash_refinements"
3
+ require "thor/error"
4
+ require "pact_broker/client/cli/pact_commands"
5
+ require "pact_broker/client/cli/environment_commands"
6
+ require "pact_broker/client/cli/deployment_commands"
7
+ require "pact_broker/client/cli/pacticipant_commands"
8
+ require "pact_broker/client/cli/version_commands"
9
+ require "pact_broker/client/cli/webhook_commands"
8
10
  require "pact_broker/client/cli/matrix_commands"
9
11
 
10
12
  module PactBroker
11
13
  module Client
12
14
  module CLI
13
- # Thor::Error will have its backtrace hidden
14
- class PactPublicationError < ::Thor::Error; end
15
- class AuthError < ::Thor::Error; end
16
- class VersionCreationError < ::Thor::Error; end
17
-
18
15
  class Broker < CustomThor
19
- using PactBroker::Client::HashRefinements
20
-
16
+ include PactBroker::Client::CLI::PactCommands
21
17
  include PactBroker::Client::CLI::EnvironmentCommands
22
18
  include PactBroker::Client::CLI::DeploymentCommands
23
19
  include PactBroker::Client::CLI::MatrixCommands
24
20
  include PactBroker::Client::CLI::PacticipantCommands
21
+ include PactBroker::Client::CLI::VersionCommands
25
22
  include PactBroker::Client::CLI::WebhookCommands
26
23
 
27
- desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
28
- method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
29
- method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
30
- method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI."
31
- method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
32
- method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
33
- method_option :build_url, desc: "The build URL that created the pact"
34
- method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
35
- output_option_json_or_text
36
- shared_authentication_options
37
-
38
- def publish(*pact_files)
39
- require 'pact_broker/client/error'
40
- validate_credentials
41
- validate_pact_files(pact_files)
42
- result = publish_pacts(pact_files)
43
- $stdout.puts result.message
44
- exit(1) unless result.success
45
- rescue PactBroker::Client::Error => e
46
- raise PactPublicationError, "#{e.class} - #{e.message}"
47
- end
48
-
49
- desc 'create-version-tag', 'Add a tag to a pacticipant version'
50
- method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
51
- method_option :version, required: true, aliases: "-e", desc: "The pacticipant version"
52
- method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
53
- method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist. Default: false"
54
- method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch. Default: false"
55
- shared_authentication_options
56
-
57
- def create_version_tag
58
- require 'pact_broker/client/create_tag'
59
-
60
- validate_credentials
61
- PactBroker::Client::CreateTag.call(
62
- options.broker_base_url,
63
- options.pacticipant,
64
- options.version,
65
- tags,
66
- options.auto_create_version,
67
- pact_broker_client_options)
68
- rescue PactBroker::Client::Error => e
69
- raise VersionCreationError.new(e.message)
70
- end
71
-
72
- method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that the version belongs to."
73
- method_option :version, required: false, aliases: "-e", desc: "The pacticipant version number."
74
- method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Describe the latest pacticipant version. Optionally specify a TAG to describe the latest version with the specified tag."
75
- method_option :output, aliases: "-o", desc: "json or table or id", default: 'table'
76
- shared_authentication_options
77
-
78
- desc 'describe-version', 'Describes a pacticipant version. If no version or tag is specified, the latest version is described.'
79
- def describe_version
80
- require 'pact_broker/client/versions/describe'
81
-
82
- validate_credentials
83
- latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
84
- params = {
85
- pacticipant: options.pacticipant,
86
- version: options.version,
87
- latest: latest,
88
- tag: options.latest != "latest" ? options.latest : nil
89
- }
90
- opts = {
91
- output: options.output
92
- }
93
- result = PactBroker::Client::Versions::Describe.call(params, opts, options.broker_base_url, pact_broker_client_options)
94
- $stdout.puts result.message
95
- exit(1) unless result.success
96
- end
97
-
98
-
99
-
100
24
  ignored_and_hidden_potential_options_from_environment_variables
101
- desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
25
+ desc "generate-uuid", "Generate a UUID for use when calling create-or-update-webhook"
102
26
  def generate_uuid
103
- require 'securerandom'
104
-
27
+ require "securerandom"
105
28
  puts SecureRandom.uuid
106
29
  end
107
30
 
108
- desc 'list-latest-pact-versions', 'List the latest pact for each integration'
109
- shared_authentication_options
110
- output_option_json_or_table
111
- def list_latest_pact_versions(*required_but_ignored)
112
- require 'pact_broker/client/pacts/list_latest_versions'
113
- result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
114
- $stdout.puts result.message
115
- exit(1) unless result.success
116
- end
117
-
118
31
  ignored_and_hidden_potential_options_from_environment_variables
119
- desc 'version', "Show the pact_broker-client gem version"
32
+ desc "version", "Show the pact_broker-client gem version"
120
33
  def version
121
- require 'pact_broker/client/version'
122
-
34
+ require "pact_broker/client/version"
123
35
  $stdout.puts PactBroker::Client::VERSION
124
36
  end
125
37
 
126
38
  no_commands do
127
-
128
39
  def self.exit_on_failure?
129
40
  true
130
41
  end
131
-
132
- def validate_credentials
133
- if options.broker_username && options.broker_token
134
- raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
135
- end
136
- end
137
-
138
- def validate_pact_files pact_files
139
- unless pact_files && pact_files.any?
140
- raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
141
- end
142
- end
143
-
144
-
145
- def publish_pacts pact_files
146
- require 'pact_broker/client/publish_pacts'
147
-
148
- write_options = options[:merge] ? { write: :merge } : {}
149
- consumer_version_params = {
150
- number: options.consumer_app_version,
151
- branch: branch,
152
- tags: tags,
153
- build_url: options.build_url,
154
- version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
155
- }.compact
156
-
157
- PactBroker::Client::PublishPacts.call(
158
- options.broker_base_url,
159
- file_list(pact_files),
160
- consumer_version_params,
161
- { merge: options[:merge], output: options.output }.compact,
162
- pact_broker_client_options.merge(write_options)
163
- )
164
- end
165
-
166
- def file_list pact_files
167
- require 'rake/file_list'
168
-
169
- correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
170
- paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
171
- if File.directory?(path)
172
- Rake::FileList[File.join(path, "*.json")]
173
- else
174
- path
175
- end
176
- end.flatten
177
- validate_pact_path_list(paths)
178
- end
179
-
180
- def validate_pact_path_list(paths)
181
- paths.collect do | path |
182
- if File.exist?(path)
183
- path
184
- elsif path.start_with?("-")
185
- raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
186
- else
187
- raise Thor::Error.new("Specified pact file '#{path}' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.")
188
- end
189
- end
190
- end
191
-
192
- def tags
193
- require 'pact_broker/client/git'
194
-
195
- t = [*options.tag]
196
- t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
197
- t.compact.uniq
198
- end
199
-
200
- def branch
201
- require 'pact_broker/client/git'
202
-
203
- if options.branch.nil? && options.auto_detect_version_properties
204
- PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
205
- else
206
- options.branch
207
- end
208
- end
209
-
210
- def explict_auto_detect_version_properties
211
- @explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
212
- end
213
-
214
- def pact_broker_client_options
215
- client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
216
- client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
217
- if options.broker_username || ENV['PACT_BROKER_USERNAME']
218
- client_options[:basic_auth] = {
219
- username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
220
- password: options.broker_password || ENV['PACT_BROKER_PASSWORD']
221
- }.compact
222
- end
223
-
224
- client_options.compact
225
- end
226
42
  end
227
43
  end
228
44
  end
@@ -1,14 +1,18 @@
1
1
  require 'thor'
2
+ require 'pact_broker/client/hash_refinements'
2
3
 
3
4
  module PactBroker
4
5
  module Client
5
6
  module CLI
7
+ class AuthError < ::Thor::Error; end
8
+
6
9
  ##
7
10
  # Custom Thor task allows the following:
8
11
  #
9
12
  # `--option 1 --option 2` to be interpreted as `--option 1 2` (the standard Thor format for multiple value options)
10
13
  #
11
14
  class CustomThor < ::Thor
15
+ using PactBroker::Client::HashRefinements
12
16
 
13
17
  no_commands do
14
18
  def self.start given_args = ARGV, config = {}
@@ -106,6 +110,25 @@ module PactBroker
106
110
  def params_from_options(keys)
107
111
  keys.each_with_object({}) { | key, p | p[key] = options[key] }
108
112
  end
113
+
114
+ def pact_broker_client_options
115
+ client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
116
+ client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
117
+ if options.broker_username || ENV['PACT_BROKER_USERNAME']
118
+ client_options[:basic_auth] = {
119
+ username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
120
+ password: options.broker_password || ENV['PACT_BROKER_PASSWORD']
121
+ }.compact
122
+ end
123
+
124
+ client_options.compact
125
+ end
126
+
127
+ def validate_credentials
128
+ if options.broker_username && options.broker_token
129
+ raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
130
+ end
131
+ end
109
132
  end
110
133
  end
111
134
  end
@@ -0,0 +1,128 @@
1
+ require "pact_broker/client/hash_refinements"
2
+
3
+ module PactBroker
4
+ module Client
5
+ module CLI
6
+ # Thor::Error will have its backtrace hidden
7
+ class PactPublicationError < ::Thor::Error; end
8
+
9
+ module PactCommands
10
+ using PactBroker::Client::HashRefinements
11
+
12
+ def self.included(thor)
13
+ thor.class_eval do
14
+ desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
15
+ method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
16
+ method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
17
+ method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI."
18
+ method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
19
+ method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
20
+ method_option :build_url, desc: "The build URL that created the pact"
21
+ method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
22
+ output_option_json_or_text
23
+ shared_authentication_options
24
+
25
+ def publish(*pact_files)
26
+ require 'pact_broker/client/error'
27
+ validate_credentials
28
+ validate_pact_files(pact_files)
29
+ result = publish_pacts(pact_files)
30
+ $stdout.puts result.message
31
+ exit(1) unless result.success
32
+ rescue PactBroker::Client::Error => e
33
+ raise PactPublicationError, "#{e.class} - #{e.message}"
34
+ end
35
+
36
+ desc 'list-latest-pact-versions', 'List the latest pact for each integration'
37
+ shared_authentication_options
38
+ output_option_json_or_table
39
+ def list_latest_pact_versions(*required_but_ignored)
40
+ require 'pact_broker/client/pacts/list_latest_versions'
41
+ result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
42
+ $stdout.puts result.message
43
+ exit(1) unless result.success
44
+ end
45
+
46
+ no_commands do
47
+ def validate_pact_files pact_files
48
+ unless pact_files && pact_files.any?
49
+ raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
50
+ end
51
+ end
52
+
53
+
54
+ def publish_pacts pact_files
55
+ require 'pact_broker/client/publish_pacts'
56
+
57
+ write_options = options[:merge] ? { write: :merge } : {}
58
+ consumer_version_params = {
59
+ number: options.consumer_app_version,
60
+ branch: branch,
61
+ tags: tags,
62
+ build_url: options.build_url,
63
+ version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
64
+ }.compact
65
+
66
+ PactBroker::Client::PublishPacts.call(
67
+ options.broker_base_url,
68
+ file_list(pact_files),
69
+ consumer_version_params,
70
+ { merge: options[:merge], output: options.output }.compact,
71
+ pact_broker_client_options.merge(write_options)
72
+ )
73
+ end
74
+
75
+ def file_list pact_files
76
+ require 'rake/file_list'
77
+
78
+ correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
79
+ paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
80
+ if File.directory?(path)
81
+ Rake::FileList[File.join(path, "*.json")]
82
+ else
83
+ path
84
+ end
85
+ end.flatten
86
+ validate_pact_path_list(paths)
87
+ end
88
+
89
+ def validate_pact_path_list(paths)
90
+ paths.collect do | path |
91
+ if File.exist?(path)
92
+ path
93
+ elsif path.start_with?("-")
94
+ raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
95
+ else
96
+ raise Thor::Error.new("Specified pact file '#{path}' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.")
97
+ end
98
+ end
99
+ end
100
+
101
+ def tags
102
+ require 'pact_broker/client/git'
103
+
104
+ t = [*options.tag]
105
+ t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
106
+ t.compact.uniq
107
+ end
108
+
109
+ def branch
110
+ require 'pact_broker/client/git'
111
+
112
+ if options.branch.nil? && options.auto_detect_version_properties
113
+ PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
114
+ else
115
+ options.branch
116
+ end
117
+ end
118
+
119
+ def explict_auto_detect_version_properties
120
+ @explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,102 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ class VersionCreationError < ::Thor::Error; end
5
+
6
+ module VersionCommands
7
+ def self.included(thor)
8
+ thor.class_eval do
9
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that the version belongs to."
10
+ method_option :version, required: false, aliases: "-e", desc: "The pacticipant version number."
11
+ method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Describe the latest pacticipant version. Optionally specify a TAG to describe the latest version with the specified tag."
12
+ method_option :output, aliases: "-o", desc: "json or table or id", default: 'table'
13
+ shared_authentication_options
14
+
15
+ desc 'describe-version', 'Describes a pacticipant version. If no version or tag is specified, the latest version is described.'
16
+ def describe_version
17
+ require 'pact_broker/client/versions/describe'
18
+
19
+ validate_credentials
20
+ latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
21
+ params = {
22
+ pacticipant: options.pacticipant,
23
+ version: options.version,
24
+ latest: latest,
25
+ tag: options.latest != "latest" ? options.latest : nil
26
+ }
27
+ opts = {
28
+ output: options.output
29
+ }
30
+ result = PactBroker::Client::Versions::Describe.call(params, opts, options.broker_base_url, pact_broker_client_options)
31
+ $stdout.puts result.message
32
+ exit(1) unless result.success
33
+ end
34
+
35
+
36
+ desc "create-or-update-version", "Create or update pacticipant version by version number"
37
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
38
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number"
39
+ method_option :branch, required: false, desc: "The repository branch name"
40
+ method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
41
+ shared_authentication_options
42
+ output_option_json_or_text
43
+ verbose_option
44
+
45
+ def create_or_update_version(*required_but_ignored)
46
+ validate_create_version_params
47
+
48
+ params = {
49
+ pacticipant_name: options.pacticipant.strip,
50
+ version_number: options.version.strip,
51
+ branch_name: options.branch&.strip,
52
+ tags: options.tag&.collect(&:strip)
53
+ }
54
+
55
+ execute_version_command(params, "Create")
56
+ end
57
+
58
+ desc 'create-version-tag', 'Add a tag to a pacticipant version'
59
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
60
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version"
61
+ method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
62
+ method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist. Default: false"
63
+ method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch. Default: false"
64
+ shared_authentication_options
65
+
66
+ def create_version_tag
67
+ require 'pact_broker/client/create_tag'
68
+
69
+ validate_credentials
70
+ PactBroker::Client::CreateTag.call(
71
+ options.broker_base_url,
72
+ options.pacticipant,
73
+ options.version,
74
+ tags,
75
+ options.auto_create_version,
76
+ pact_broker_client_options)
77
+ rescue PactBroker::Client::Error => e
78
+ raise VersionCreationError.new(e.message)
79
+ end
80
+
81
+ no_commands do
82
+ def execute_version_command(params, command_class_name)
83
+ require "pact_broker/client/versions"
84
+ command_options = { verbose: options.verbose, output: options.output }
85
+ result = PactBroker::Client::Versions.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
86
+ $stdout.puts result.message
87
+ exit(1) unless result.success
88
+ end
89
+
90
+ def validate_create_version_params
91
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.pacticipant.strip.size == 0
92
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant version cannot be blank" if options.version.strip.size == 0
93
+ raise ::Thor::RequiredArgumentMissingError, "Version branch cannot be blank" if options.branch && options.branch.strip.size == 0
94
+ raise ::Thor::RequiredArgumentMissingError, "Version tag cannot be blank" if options.tag && options.tag.any?{ | tag | tag.strip.size == 0 }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,9 +1,12 @@
1
1
  require 'pact_broker/client/deployments/record_release'
2
+ require "pact_broker/client/hash_refinements"
2
3
 
3
4
  module PactBroker
4
5
  module Client
5
6
  module Deployments
6
7
  class RecordDeployment < PactBroker::Client::Deployments::RecordRelease
8
+ using PactBroker::Client::HashRefinements
9
+
7
10
  def initialize(params, options, pact_broker_client_options)
8
11
  super
9
12
  @application_instance = params.fetch(:application_instance)
@@ -1,9 +1,12 @@
1
1
  require 'pact_broker/client/base_command'
2
+ require 'pact_broker/client/hash_refinements'
2
3
 
3
4
  module PactBroker
4
5
  module Client
5
6
  module Deployments
6
7
  class RecordUndeployment < PactBroker::Client::BaseCommand
8
+ using PactBroker::Client::HashRefinements
9
+
7
10
  def initialize(params, options, pact_broker_client_options)
8
11
  super
9
12
  @pacticipant_name = params.fetch(:pacticipant_name)
@@ -1,9 +1,12 @@
1
1
  require 'pact_broker/client/base_command'
2
+ require 'pact_broker/client/hash_refinements'
2
3
 
3
4
  module PactBroker
4
5
  module Client
5
6
  module Environments
6
7
  class EnvironmentCommand < PactBroker::Client::BaseCommand
8
+ using PactBroker::Client::HashRefinements
9
+
7
10
  NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support environments. Please upgrade to version 2.80.0 or later."
8
11
  PACTFLOW_NOT_SUPPORTED_MESSAGE = "This version of Pactflow does not support environments or you do not have the required permission to read them. Please upgrade to the latest version if using Pactflow On-Premises and ensure the user has the environment read permission."
9
12
 
@@ -1,10 +1,13 @@
1
1
  require 'uri'
2
2
  require 'delegate'
3
+ require 'pact_broker/client/hash_refinements'
3
4
 
4
5
  module PactBroker
5
6
  module Client
6
7
  module Hal
7
8
  class Links
9
+ using PactBroker::Client::HashRefinements
10
+
8
11
  def initialize(href, key, links)
9
12
  @href = href
10
13
  @key = key
@@ -13,6 +13,15 @@ module PactBroker
13
13
  def compact!
14
14
  reject! {|_key, value| value == nil}
15
15
  end unless Hash.method_defined? :compact!
16
+
17
+ def except(*keys)
18
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
19
+ h = {}
20
+ keys.each { |key| h[key] = true }
21
+ keys = h
22
+ end
23
+ reject { |key, _value| keys.include? key}
24
+ end unless method_defined? :except
16
25
  end
17
26
  end
18
27
  end
@@ -30,7 +30,7 @@ module PactBroker
30
30
  if json_output?
31
31
  response_entity.response.raw_body
32
32
  else
33
- green(message = "Pacticipant \"#{params[:name]}\" #{action} in #{pact_broker_name}")
33
+ green("Pacticipant \"#{params[:name]}\" #{action} in #{pact_broker_name}")
34
34
  end
35
35
  end
36
36
 
@@ -3,6 +3,7 @@ require 'pact_broker/client/hal_client_methods'
3
3
  require 'base64'
4
4
  require 'pact_broker/client/publish_pacts_the_old_way'
5
5
  require 'pact_broker/client/colorize_notices'
6
+ require 'pact_broker/client/hash_refinements'
6
7
 
7
8
  module PactBroker
8
9
  module Client
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.60.0'
3
+ VERSION = '1.61.0'
4
4
  end
5
5
  end
@@ -0,0 +1,111 @@
1
+ require "pact_broker/client/base_client"
2
+ require "pact_broker/client/base_command"
3
+
4
+ module PactBroker
5
+ module Client
6
+ class Versions < BaseClient # need to retire the old base client code
7
+ class Create < PactBroker::Client::BaseCommand
8
+
9
+ def do_call
10
+ if branch_name
11
+ if branch_versions_supported?
12
+ create_branch_version
13
+ else
14
+ raise PactBroker::Client::Error.new("This version of #{pact_broker_name} does not support branch versions,or you do not have the required permissions to create one. Please ensure you have upgraded to version 2.82.0 or later for branch support.")
15
+ end
16
+ end
17
+
18
+ if tags
19
+ create_version_tags
20
+ end
21
+
22
+ if !branch_name && !tags.any?
23
+ create_version
24
+ end
25
+
26
+ PactBroker::Client::CommandResult.new(true, result_message)
27
+ end
28
+
29
+ private
30
+
31
+ def pacticipant_name
32
+ params.fetch(:pacticipant_name)
33
+ end
34
+
35
+ def version_number
36
+ params.fetch(:version_number)
37
+ end
38
+
39
+ def branch_name
40
+ params[:branch_name]
41
+ end
42
+
43
+ def tags
44
+ params[:tags] || []
45
+ end
46
+
47
+ def branch_versions_supported?
48
+ index_resource._link("pb:pacticipant-branch-version")
49
+ end
50
+
51
+ def create_branch_version
52
+ branch_params = {
53
+ "pacticipant" => pacticipant_name,
54
+ "version" => version_number,
55
+ "branch" => branch_name
56
+ }
57
+ branch_version_entity = index_resource
58
+ ._link("pb:pacticipant-branch-version")
59
+ .expand(branch_params)
60
+ .put!
61
+ end
62
+
63
+ def create_version_tags
64
+ tags.each do | tag |
65
+ tag_params = {
66
+ "pacticipant" => pacticipant_name,
67
+ "version" => version_number,
68
+ "tag" => tag
69
+ }
70
+ index_resource
71
+ ._link("pb:pacticipant-version-tag")
72
+ .expand(tag_params)
73
+ .put!
74
+ end
75
+ end
76
+
77
+ def create_version
78
+ @version_resource ||= expanded_version_relation.put!
79
+ end
80
+
81
+ def expanded_version_relation
82
+ version_params = {
83
+ "pacticipant" => pacticipant_name,
84
+ "version" => version_number
85
+ }
86
+ index_resource
87
+ ._link("pb:pacticipant-version")
88
+ .expand(version_params)
89
+ end
90
+
91
+ def result_message
92
+ if json_output?
93
+ (@version_resource || expanded_version_relation.get).response.raw_body
94
+ else
95
+ message = "Created/updated pacticipant version #{version_number}"
96
+ if branch_name && tags.any?
97
+ message = message + " with branch #{branch_name} and tag(s) #{tags.join(", ")}"
98
+ elsif branch_name
99
+ message = message + " with branch #{branch_name}"
100
+ elsif tags.any?
101
+ message = message + " with tag(s) #{tags.join(", ")}"
102
+ end
103
+
104
+ message = message + " in #{pact_broker_name}"
105
+ green(message)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,5 +1,6 @@
1
1
  require 'pact_broker/client/base_client'
2
2
  require 'pact_broker/client/versions/describe'
3
+ require 'pact_broker/client/versions/create'
3
4
 
4
5
  # Old code
5
6
  require 'pact_broker/client/pacts'
@@ -4,11 +4,14 @@ require 'ostruct'
4
4
  require 'json'
5
5
  require 'pact_broker/client/command_result'
6
6
  require "pact_broker/client/backports"
7
+ require "pact_broker/client/hash_refinements"
7
8
 
8
9
  module PactBroker
9
10
  module Client
10
11
  module Webhooks
11
12
  class Create
13
+ using PactBroker::Client::HashRefinements
14
+
12
15
  WEBHOOKS_WITH_OPTIONAL_PACTICICPANTS_NOT_SUPPORTED = "This version of the Pact Broker requires that both consumer and provider are specified for a webhook. Please upgrade your broker to >= 2.22.0 to create a webhook with optional consumer and provider."
13
16
  CREATING_WEBHOOK_WITH_UUID_NOT_SUPPORTED = "This version of the Pact Broker does not support creating webhooks with a specified UUID. Please upgrade your broker to >= 2.49.0 or use the create-webhook command."
14
17
 
@@ -1,4 +1,4 @@
1
1
  bundle exec bin/pact-broker record-undeployment \
2
- --pacticipant foo-consumer --version 1 --environment prod --broker-base-url http://localhost:9292 --output json --verbose
2
+ --pacticipant foo-consumer --environment production --broker-base-url http://localhost:9292 --output json --verbose
3
3
 
4
4
 
@@ -58,7 +58,7 @@ def generate_thor_docs
58
58
  ["Pacticipants", %w[create-or-update-pacticipant describe-pacticipant list-pacticipants]],
59
59
  ["Webhooks", %w[create-webhook create-or-update-webhook test-webhook]],
60
60
  ["Tags", %w[create-version-tag]],
61
- ["Versions", %w[describe-version]],
61
+ ["Versions", %w[describe-version create-or-update-version]],
62
62
  ["Miscellaneous", %w[generate-uuid]]
63
63
  ]
64
64
 
@@ -0,0 +1,174 @@
1
+ require "pact_broker/client/versions/create"
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe Versions::Create do
6
+ describe "#call" do
7
+ let(:index_body) do
8
+ {
9
+ "_links" => {
10
+ "pb:pacticipant-branch-version" => {
11
+ "href" => "http://broker/pacticipants/{pacticipant}/branches/{branch}/versions/{version}"
12
+ },
13
+ "pb:pacticipant-version-tag" => {
14
+ "href" => "http://broker/pacticipants/{pacticipant}/versions/{version}/tags/{tag}"
15
+ },
16
+ "pb:pacticipant-version" => {
17
+ "href" => "http://broker/pacticipants/{pacticipant}/versions/{version}"
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ let!(:index_request) do
24
+ stub_request(:get, "http://broker").to_return(status: 200, body: index_body.to_json, headers: { "Content-Type" => "application/hal+json" } )
25
+ end
26
+
27
+ let!(:branch_request) do
28
+ stub_request(:put, "http://broker/pacticipants/Foo/branches/main/versions/1").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
29
+ end
30
+
31
+ let!(:tag_request) do
32
+ stub_request(:put, "http://broker/pacticipants/Foo/versions/1/tags/dev").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
33
+ end
34
+
35
+ let!(:create_version_request) do
36
+ stub_request(:put, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "created" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
37
+ end
38
+
39
+ let!(:get_version_request) do
40
+ stub_request(:get, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "got" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
41
+ end
42
+
43
+ let(:params) do
44
+ {
45
+ pacticipant_name: "Foo",
46
+ version_number: "1",
47
+ branch_name: branch_name,
48
+ tags: tags
49
+ }
50
+ end
51
+
52
+ let(:branch_name) { "main" }
53
+ let(:tags) { ["dev"] }
54
+
55
+ let(:options) do
56
+ {
57
+ verbose: "verbose",
58
+ output: output
59
+ }
60
+ end
61
+
62
+ let(:output) { "text" }
63
+
64
+ let(:pact_broker_client_options) do
65
+ {
66
+ token: "token",
67
+ pact_broker_base_url: "http://broker"
68
+ }
69
+ end
70
+
71
+ subject { PactBroker::Client::Versions::Create.call(params, options, pact_broker_client_options)}
72
+
73
+ context "with a branch and tags" do
74
+ it "creates a branch version" do
75
+ subject
76
+ expect(branch_request).to have_been_made
77
+ end
78
+
79
+ it "creates the tag" do
80
+ subject
81
+ expect(tag_request).to have_been_made
82
+ end
83
+
84
+ it "returns a message" do
85
+ expect(subject.message).to include "Created/updated pacticipant version 1 with branch main and tag(s) dev in the Pact Broker"
86
+ expect(subject.success).to be true
87
+ end
88
+
89
+ context "without output json" do
90
+ let(:output) { "json" }
91
+
92
+ it "returns a json message" do
93
+ expect(subject.message).to eq({ version: "got" }.to_json)
94
+ end
95
+ end
96
+ end
97
+
98
+ context "with only tags" do
99
+ let(:branch_name) { nil }
100
+
101
+ it "returns a message" do
102
+ expect(subject.message).to include "Created/updated pacticipant version 1 with tag(s) dev in the Pact Broker"
103
+ expect(subject.success).to be true
104
+ end
105
+
106
+ context "without output json" do
107
+ let(:output) { "json" }
108
+
109
+ it "returns a json message" do
110
+ expect(subject.message).to eq({ version: "got" }.to_json)
111
+ end
112
+ end
113
+ end
114
+
115
+ context "with only a branch" do
116
+ let(:tags) { nil }
117
+
118
+ it "returns a message" do
119
+ expect(subject.message).to include "Created/updated pacticipant version 1 with branch main in the Pact Broker"
120
+ expect(subject.success).to be true
121
+ end
122
+
123
+ context "without output json" do
124
+ let(:output) { "json" }
125
+
126
+ it "returns a json message" do
127
+ expect(subject.message).to eq({ version: "got" }.to_json)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "with no branch or tags" do
133
+ let(:tags) { nil }
134
+ let(:branch_name) { nil }
135
+
136
+ it "creates a version" do
137
+ subject
138
+ expect(create_version_request).to have_been_made
139
+ end
140
+
141
+ it "returns a message" do
142
+ expect(subject.message).to include "Created/updated pacticipant version 1 in the Pact Broker"
143
+ expect(subject.success).to be true
144
+ end
145
+
146
+ context "without output json" do
147
+ let(:output) { "json" }
148
+
149
+ it "returns a json message" do
150
+ expect(subject.message).to eq({ version: "created" }.to_json)
151
+ end
152
+ end
153
+ end
154
+
155
+ context "when the Pact Broker does not support branch versions" do
156
+ before do
157
+ index_body["_links"].delete("pb:pacticipant-branch-version")
158
+ end
159
+
160
+ let(:index_body) do
161
+ {
162
+ "_links" => {}
163
+ }
164
+ end
165
+
166
+ it "returns an error" do
167
+ expect(subject.message).to include "does not support branch versions"
168
+ expect(subject.success).to be false
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.60.0
4
+ version: 1.61.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -245,8 +245,10 @@ files:
245
245
  - lib/pact_broker/client/cli/deployment_commands.rb
246
246
  - lib/pact_broker/client/cli/environment_commands.rb
247
247
  - lib/pact_broker/client/cli/matrix_commands.rb
248
+ - lib/pact_broker/client/cli/pact_commands.rb
248
249
  - lib/pact_broker/client/cli/pacticipant_commands.rb
249
250
  - lib/pact_broker/client/cli/record_deployment_long_desc.txt
251
+ - lib/pact_broker/client/cli/version_commands.rb
250
252
  - lib/pact_broker/client/cli/version_selector_options_parser.rb
251
253
  - lib/pact_broker/client/cli/webhook_commands.rb
252
254
  - lib/pact_broker/client/colorize_notices.rb
@@ -304,6 +306,7 @@ files:
304
306
  - lib/pact_broker/client/verification_required.rb
305
307
  - lib/pact_broker/client/version.rb
306
308
  - lib/pact_broker/client/versions.rb
309
+ - lib/pact_broker/client/versions/create.rb
307
310
  - lib/pact_broker/client/versions/describe.rb
308
311
  - lib/pact_broker/client/versions/formatter.rb
309
312
  - lib/pact_broker/client/versions/json_formatter.rb
@@ -365,6 +368,7 @@ files:
365
368
  - spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
366
369
  - spec/lib/pact_broker/client/retry_spec.rb
367
370
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
371
+ - spec/lib/pact_broker/client/versions/create_spec.rb
368
372
  - spec/lib/pact_broker/client/versions/describe_spec.rb
369
373
  - spec/lib/pact_broker/client/versions_spec.rb
370
374
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
@@ -425,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
429
  - !ruby/object:Gem::Version
426
430
  version: '0'
427
431
  requirements: []
428
- rubygems_version: 3.3.12
432
+ rubygems_version: 3.3.13
429
433
  signing_key:
430
434
  specification_version: 4
431
435
  summary: See description
@@ -472,6 +476,7 @@ test_files:
472
476
  - spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
473
477
  - spec/lib/pact_broker/client/retry_spec.rb
474
478
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
479
+ - spec/lib/pact_broker/client/versions/create_spec.rb
475
480
  - spec/lib/pact_broker/client/versions/describe_spec.rb
476
481
  - spec/lib/pact_broker/client/versions_spec.rb
477
482
  - spec/lib/pact_broker/client/webhooks/create_spec.rb