pact_broker-client 1.38.2 → 1.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +47 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +61 -140
- data/example/scripts/publish-pact.sh +1 -1
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_client.rb +1 -1
- data/lib/pact_broker/client/base_command.rb +95 -0
- data/lib/pact_broker/client/can_i_deploy.rb +20 -3
- data/lib/pact_broker/client/cli/broker.rb +44 -28
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
- data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +44 -0
- data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -0
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
- data/lib/pact_broker/client/colorize_notices.rb +31 -0
- data/lib/pact_broker/client/environments.rb +3 -0
- data/lib/pact_broker/client/environments/create_environment.rb +31 -0
- data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
- data/lib/pact_broker/client/environments/describe_environment.rb +36 -0
- data/lib/pact_broker/client/environments/environment_command.rb +66 -0
- data/lib/pact_broker/client/environments/list_environments.rb +30 -0
- data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
- data/lib/pact_broker/client/environments/update_environment.rb +31 -0
- data/lib/pact_broker/client/generate_display_name.rb +27 -0
- data/lib/pact_broker/client/hal/entity.rb +26 -3
- data/lib/pact_broker/client/hal/http_client.rb +11 -2
- data/lib/pact_broker/client/hal/link.rb +20 -0
- data/lib/pact_broker/client/hal/links.rb +15 -0
- data/lib/pact_broker/client/hal_client_methods.rb +9 -3
- data/lib/pact_broker/client/matrix.rb +4 -0
- data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
- data/lib/pact_broker/client/matrix/resource.rb +26 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
- data/lib/pact_broker/client/pacticipants.rb +6 -0
- data/lib/pact_broker/client/pacticipants/create.rb +24 -34
- data/lib/pact_broker/client/pacticipants/list.rb +34 -0
- data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
- data/lib/pact_broker/client/pacts.rb +0 -1
- data/lib/pact_broker/client/publish_pacts.rb +94 -128
- data/lib/pact_broker/client/publish_pacts_the_old_way.rb +194 -0
- data/lib/pact_broker/client/string_refinements.rb +56 -0
- data/lib/pact_broker/client/tasks/publication_task.rb +3 -3
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/record_deployment.rb +6 -6
- data/lib/pact_broker/client/versions/record_undeployment.rb +45 -68
- data/pact-broker-client.gemspec +2 -0
- data/script/approve-all.sh +6 -0
- data/script/publish-pact.sh +36 -5
- data/script/record-deployment.sh +1 -3
- data/script/record-undeployment.sh +4 -0
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
- data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
- data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
- data/spec/fixtures/foo-bar.json +31 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +36 -7
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +5 -2
- data/spec/lib/pact_broker/client/{publish_pacts_spec.rb → publish_pacts_the_old_way_spec.rb} +10 -9
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +18 -12
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +5 -5
- data/spec/pacts/pact_broker_client-pact_broker.json +50 -124
- data/spec/service_providers/create_environment_spec.rb +78 -0
- data/spec/service_providers/list_environments_spec.rb +77 -0
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +4 -4
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
- data/spec/service_providers/pacticipants_create_spec.rb +5 -4
- data/spec/service_providers/publish_pacts_spec.rb +116 -0
- data/spec/service_providers/record_deployment_spec.rb +6 -7
- data/spec/spec_helper.rb +3 -1
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +6 -2
- metadata +86 -5
@@ -3,6 +3,7 @@ require 'pact_broker/client/pact_broker_client'
|
|
3
3
|
require 'pact_broker/client/retry'
|
4
4
|
require 'pact_broker/client/matrix/formatter'
|
5
5
|
require 'term/ansicolor'
|
6
|
+
require 'pact_broker/client/colorize_notices'
|
6
7
|
|
7
8
|
module PactBroker
|
8
9
|
module Client
|
@@ -32,7 +33,7 @@ module PactBroker
|
|
32
33
|
def call
|
33
34
|
create_result(fetch_matrix_with_retries)
|
34
35
|
rescue PactBroker::Client::Error => e
|
35
|
-
Result.new(false, e.message)
|
36
|
+
Result.new(false, Term::ANSIColor.red(e.message))
|
36
37
|
rescue StandardError => e
|
37
38
|
Result.new(false, "Error retrieving matrix. #{e.class} - #{e.message}\n#{e.backtrace.join("\n")}")
|
38
39
|
end
|
@@ -52,7 +53,7 @@ module PactBroker
|
|
52
53
|
def success_message(matrix)
|
53
54
|
message = format_matrix(matrix)
|
54
55
|
if format != 'json'
|
55
|
-
message = 'Computer says yes \o/ ' + message + "\n\n" +
|
56
|
+
message = warning(matrix) + Term::ANSIColor.green('Computer says yes \o/ ') + message + "\n\n" + notice_or_reason(matrix, :green)
|
56
57
|
end
|
57
58
|
message
|
58
59
|
end
|
@@ -60,11 +61,19 @@ module PactBroker
|
|
60
61
|
def failure_message(matrix)
|
61
62
|
message = format_matrix(matrix)
|
62
63
|
if format != 'json'
|
63
|
-
message = 'Computer says no ¯\_(ツ)_/¯ ' + message + "\n\n" +
|
64
|
+
message = warning(matrix) + Term::ANSIColor.red('Computer says no ¯\_(ツ)_/¯ ') + message + "\n\n" + notice_or_reason(matrix, :red)
|
64
65
|
end
|
65
66
|
message
|
66
67
|
end
|
67
68
|
|
69
|
+
def notice_or_reason(matrix, reason_color)
|
70
|
+
if matrix.notices
|
71
|
+
PactBroker::Client::ColorizeNotices.call(matrix.notices).join("\n")
|
72
|
+
else
|
73
|
+
Term::ANSIColor.send(reason_color, matrix.reason)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
68
77
|
def format_matrix(matrix)
|
69
78
|
formatted_matrix = Matrix::Formatter.call(matrix, format)
|
70
79
|
if format != 'json' && formatted_matrix.size > 0
|
@@ -131,6 +140,14 @@ module PactBroker
|
|
131
140
|
raise PactBroker::Client::Error.new("This version of the Pact Broker does not provide a count of the unknown verification results. Please upgrade your Broker to >= v2.23.4")
|
132
141
|
end
|
133
142
|
end
|
143
|
+
|
144
|
+
def warning(matrix)
|
145
|
+
if matrix_options[:ignore_selectors] && matrix_options[:ignore_selectors].any? && !matrix.supports_ignore?
|
146
|
+
Term::ANSIColor.yellow("WARN: This version of the Pact Broker does not support ignoring pacticipants. Please upgrade your Broker to >= 2.80.0") + "\n\n"
|
147
|
+
else
|
148
|
+
""
|
149
|
+
end
|
150
|
+
end
|
134
151
|
end
|
135
152
|
end
|
136
153
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'pact_broker/client/cli/custom_thor'
|
2
2
|
require 'pact_broker/client/hash_refinements'
|
3
3
|
require 'thor/error'
|
4
|
+
require 'pact_broker/client/cli/environment_commands'
|
5
|
+
require 'pact_broker/client/cli/pacticipant_commands'
|
4
6
|
|
5
7
|
module PactBroker
|
6
8
|
module Client
|
@@ -13,12 +15,20 @@ module PactBroker
|
|
13
15
|
|
14
16
|
class Broker < CustomThor
|
15
17
|
using PactBroker::Client::HashRefinements
|
18
|
+
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
19
|
+
include PactBroker::Client::CLI::EnvironmentCommands
|
20
|
+
end
|
21
|
+
include PactBroker::Client::CLI::PacticipantCommands
|
16
22
|
|
17
23
|
desc 'can-i-deploy', ''
|
18
|
-
long_desc File.read(File.join(
|
24
|
+
long_desc File.read(File.join(__dir__, 'can_i_deploy_long_desc.txt'))
|
19
25
|
|
20
26
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
21
27
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
28
|
+
|
29
|
+
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
|
30
|
+
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version."
|
31
|
+
end
|
22
32
|
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
|
23
33
|
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
|
24
34
|
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
|
@@ -34,10 +44,15 @@ module PactBroker
|
|
34
44
|
require 'pact_broker/client/can_i_deploy'
|
35
45
|
|
36
46
|
validate_credentials
|
37
|
-
selectors = VersionSelectorOptionsParser.call(ARGV)
|
47
|
+
selectors = VersionSelectorOptionsParser.call(ARGV).select { |s| !s[:ignore] }
|
48
|
+
ignore_selectors = if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
|
49
|
+
VersionSelectorOptionsParser.call(ARGV).select { |s| s[:ignore] }
|
50
|
+
else
|
51
|
+
[]
|
52
|
+
end
|
38
53
|
validate_can_i_deploy_selectors(selectors)
|
39
54
|
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
|
40
|
-
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
|
55
|
+
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit, ignore_selectors: ignore_selectors }, can_i_deploy_options, pact_broker_client_options)
|
41
56
|
$stdout.puts result.message
|
42
57
|
$stdout.flush
|
43
58
|
exit(can_i_deploy_exit_status) unless result.success
|
@@ -51,14 +66,16 @@ module PactBroker
|
|
51
66
|
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"
|
52
67
|
method_option :build_url, desc: "The build URL that created the pact"
|
53
68
|
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."
|
69
|
+
output_option_json_or_text
|
54
70
|
shared_authentication_options
|
55
71
|
|
56
72
|
def publish(*pact_files)
|
57
73
|
require 'pact_broker/client/error'
|
58
74
|
validate_credentials
|
59
75
|
validate_pact_files(pact_files)
|
60
|
-
|
61
|
-
|
76
|
+
result = publish_pacts(pact_files)
|
77
|
+
$stdout.puts result.message
|
78
|
+
exit(1) unless result.success
|
62
79
|
rescue PactBroker::Client::Error => e
|
63
80
|
raise PactPublicationError, "#{e.class} - #{e.message}"
|
64
81
|
end
|
@@ -146,22 +163,9 @@ module PactBroker
|
|
146
163
|
puts SecureRandom.uuid
|
147
164
|
end
|
148
165
|
|
149
|
-
desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
|
150
|
-
method_option :name, type: :string, required: true, desc: "Pacticipant name"
|
151
|
-
method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
|
152
|
-
shared_authentication_options
|
153
|
-
verbose_option
|
154
|
-
def create_or_update_pacticipant(*required_but_ignored)
|
155
|
-
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
|
156
|
-
require 'pact_broker/client/pacticipants/create'
|
157
|
-
result = PactBroker::Client::Pacticipants2::Create.call({ name: options.name, repository_url: options.repository_url }, options.broker_base_url, pact_broker_client_options)
|
158
|
-
$stdout.puts result.message
|
159
|
-
exit(1) unless result.success
|
160
|
-
end
|
161
|
-
|
162
166
|
desc 'list-latest-pact-versions', 'List the latest pact for each integration'
|
163
167
|
shared_authentication_options
|
164
|
-
|
168
|
+
output_option_json_or_table
|
165
169
|
def list_latest_pact_versions(*required_but_ignored)
|
166
170
|
require 'pact_broker/client/pacts/list_latest_versions'
|
167
171
|
result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
|
@@ -170,14 +174,13 @@ module PactBroker
|
|
170
174
|
end
|
171
175
|
|
172
176
|
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
173
|
-
|
174
177
|
ignored_and_hidden_potential_options_from_environment_variables
|
175
|
-
desc "record-deployment", "Record deployment of a pacticipant version to an environment"
|
178
|
+
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See https://docs.pact.io/go/record_deployment for more information."
|
176
179
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
177
180
|
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
178
181
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
179
|
-
method_option :
|
180
|
-
|
182
|
+
method_option :target, default: nil, required: false, desc: "Optional. The target of the deployment - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
|
183
|
+
output_option_json_or_text
|
181
184
|
shared_authentication_options
|
182
185
|
|
183
186
|
def record_deployment
|
@@ -186,7 +189,7 @@ module PactBroker
|
|
186
189
|
pacticipant_name: options.pacticipant,
|
187
190
|
version_number: options.version,
|
188
191
|
environment_name: options.environment,
|
189
|
-
|
192
|
+
target: options.target,
|
190
193
|
output: options.output
|
191
194
|
}
|
192
195
|
result = PactBroker::Client::Versions::RecordDeployment.call(
|
@@ -203,7 +206,7 @@ module PactBroker
|
|
203
206
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
204
207
|
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
205
208
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
206
|
-
|
209
|
+
output_option_json_or_text
|
207
210
|
shared_authentication_options
|
208
211
|
|
209
212
|
def record_undeployment
|
@@ -282,6 +285,7 @@ module PactBroker
|
|
282
285
|
options.broker_base_url,
|
283
286
|
file_list(pact_files),
|
284
287
|
consumer_version_params,
|
288
|
+
{ merge: options[:merge], output: options.output }.compact,
|
285
289
|
pact_broker_client_options.merge(write_options)
|
286
290
|
)
|
287
291
|
end
|
@@ -290,13 +294,26 @@ module PactBroker
|
|
290
294
|
require 'rake/file_list'
|
291
295
|
|
292
296
|
correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
|
293
|
-
Rake::FileList[correctly_separated_pact_files].collect do | path |
|
297
|
+
paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
|
294
298
|
if File.directory?(path)
|
295
299
|
Rake::FileList[File.join(path, "*.json")]
|
296
300
|
else
|
297
301
|
path
|
298
302
|
end
|
299
303
|
end.flatten
|
304
|
+
validate_pact_path_list(paths)
|
305
|
+
end
|
306
|
+
|
307
|
+
def validate_pact_path_list(paths)
|
308
|
+
paths.collect do | path |
|
309
|
+
if File.exist?(path)
|
310
|
+
path
|
311
|
+
elsif path.start_with?("-")
|
312
|
+
raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
|
313
|
+
else
|
314
|
+
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.")
|
315
|
+
end
|
316
|
+
end
|
300
317
|
end
|
301
318
|
|
302
319
|
def tags
|
@@ -322,7 +339,7 @@ module PactBroker
|
|
322
339
|
end
|
323
340
|
|
324
341
|
def pact_broker_client_options
|
325
|
-
client_options = { verbose: options.verbose }
|
342
|
+
client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
|
326
343
|
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
327
344
|
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
328
345
|
client_options[:basic_auth] = {
|
@@ -379,7 +396,6 @@ module PactBroker
|
|
379
396
|
provider: options.provider,
|
380
397
|
events: events
|
381
398
|
}
|
382
|
-
|
383
399
|
end
|
384
400
|
|
385
401
|
def run_webhook_commands webhook_url
|
@@ -110,6 +110,18 @@ module PactBroker
|
|
110
110
|
def self.verbose_option
|
111
111
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
112
112
|
end
|
113
|
+
|
114
|
+
def self.output_option_json_or_text
|
115
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.output_option_json_or_table
|
119
|
+
method_option :output, aliases: "-o", desc: "json or table", default: 'table'
|
120
|
+
end
|
121
|
+
|
122
|
+
def params_from_options(keys)
|
123
|
+
keys.each_with_object({}) { | key, p | p[key] = options[key] }
|
124
|
+
end
|
113
125
|
end
|
114
126
|
end
|
115
127
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module CLI
|
4
|
+
module EnvironmentCommands
|
5
|
+
ENVIRONMENT_PARAM_NAMES = [:name, :display_name, :production, :contact_name, :contact_email_address]
|
6
|
+
|
7
|
+
def self.included(thor)
|
8
|
+
thor.class_eval do
|
9
|
+
def self.shared_environment_options(name_required: false)
|
10
|
+
method_option :name, required: name_required, desc: "The uniquely identifying name of the environment as used in deployment code"
|
11
|
+
method_option :display_name, desc: "The display name of the environment"
|
12
|
+
method_option :production, type: :boolean, default: false, desc: "Whether or not this environment is a production environment. Default: false"
|
13
|
+
method_option :contact_name, required: false, desc: "The name of the team/person responsible for this environment"
|
14
|
+
method_option :contact_email_address, required: false, desc: "The email address of the team/person responsible for this environment"
|
15
|
+
output_option_json_or_text
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "create-environment", "Create an environment resource in the Pact Broker to represent a real world deployment or release environment."
|
19
|
+
shared_environment_options(name_required: true)
|
20
|
+
shared_authentication_options
|
21
|
+
def create_environment
|
22
|
+
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "update-environment", "Update an environment resource in the Pact Broker."
|
26
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to update"
|
27
|
+
shared_environment_options(name_required: false)
|
28
|
+
shared_authentication_options
|
29
|
+
def update_environment
|
30
|
+
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "describe-environment", "Describe an environment"
|
34
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to describe"
|
35
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
36
|
+
shared_authentication_options
|
37
|
+
def describe_environment
|
38
|
+
execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "list-environments", "List environment"
|
42
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
43
|
+
shared_authentication_options
|
44
|
+
def list_environments
|
45
|
+
execute_environment_command({}, "ListEnvironments")
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "delete-environment", "Delete an environment"
|
49
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to delete"
|
50
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
51
|
+
shared_authentication_options
|
52
|
+
def delete_environment
|
53
|
+
execute_environment_command(params_from_options([:uuid]), "DeleteEnvironment")
|
54
|
+
end
|
55
|
+
|
56
|
+
no_commands do
|
57
|
+
def execute_environment_command(params, command_class_name)
|
58
|
+
require 'pact_broker/client/environments'
|
59
|
+
command_options = { verbose: options.verbose, output: options.output }
|
60
|
+
result = PactBroker::Client::Environments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
|
61
|
+
$stdout.puts result.message
|
62
|
+
exit(1) unless result.success
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module CLI
|
4
|
+
module PacticipantCommands
|
5
|
+
PACTICIPANT_PARAM_NAMES = [:name, :display_name, :repository_url]
|
6
|
+
|
7
|
+
def self.included(thor)
|
8
|
+
thor.class_eval do
|
9
|
+
desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
|
10
|
+
method_option :name, type: :string, required: true, desc: "Pacticipant name"
|
11
|
+
method_option :display_name, type: :string, desc: "Display name"
|
12
|
+
method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
|
13
|
+
output_option_json_or_text
|
14
|
+
shared_authentication_options
|
15
|
+
verbose_option
|
16
|
+
|
17
|
+
def create_or_update_pacticipant(*required_but_ignored)
|
18
|
+
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
|
19
|
+
execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'Create')
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'list-pacticipants', 'List pacticipants'
|
23
|
+
output_option_json_or_text
|
24
|
+
shared_authentication_options
|
25
|
+
verbose_option
|
26
|
+
def list_pacticipants
|
27
|
+
execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'List')
|
28
|
+
end
|
29
|
+
|
30
|
+
no_commands do
|
31
|
+
def execute_pacticipant_command(params, command_class_name)
|
32
|
+
require 'pact_broker/client/pacticipants'
|
33
|
+
command_options = { verbose: options.verbose, output: options.output }
|
34
|
+
result = PactBroker::Client::Pacticipants2.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
|
35
|
+
$stdout.puts result.message
|
36
|
+
exit(1) unless result.success
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
File without changes
|
@@ -12,6 +12,8 @@ module PactBroker
|
|
12
12
|
case word
|
13
13
|
when "--pacticipant", "-a"
|
14
14
|
selectors << {}
|
15
|
+
when "--ignore"
|
16
|
+
selectors << { ignore: true }
|
15
17
|
when "--latest", "-l"
|
16
18
|
selectors << { pacticipant: nil } if selectors.empty?
|
17
19
|
selectors.last[:latest] = true
|
@@ -21,6 +23,8 @@ module PactBroker
|
|
21
23
|
case previous_option
|
22
24
|
when "--pacticipant", "-a"
|
23
25
|
selectors.last[:pacticipant] = word
|
26
|
+
when "--ignore"
|
27
|
+
selectors.last[:pacticipant] = word
|
24
28
|
when "--version", "-e"
|
25
29
|
selectors << { pacticipant: nil } if selectors.empty?
|
26
30
|
selectors.last[:version] = word
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
class ColorizeNotices
|
6
|
+
def self.call(notices)
|
7
|
+
notices.collect do | notice |
|
8
|
+
colorized_message(notice)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.colorized_message(notice)
|
13
|
+
color = color_for_type(notice.type)
|
14
|
+
if color
|
15
|
+
::Term::ANSIColor.color(color, notice.text || '')
|
16
|
+
else
|
17
|
+
notice.text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.color_for_type(type)
|
22
|
+
case type
|
23
|
+
when "warning", "prompt" then "yellow"
|
24
|
+
when "error", "danger" then :red
|
25
|
+
when "success" then :green
|
26
|
+
else nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'pact_broker/client/environments/environment_command'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Environments
|
6
|
+
class CreateEnvironment < PactBroker::Client::Environments::EnvironmentCommand
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
attr_reader :created_environment_resource
|
11
|
+
|
12
|
+
def do_call
|
13
|
+
@created_environment_resource = environments_link.post!(new_environment_body)
|
14
|
+
PactBroker::Client::CommandResult.new(created_environment_resource.success?, result_message)
|
15
|
+
end
|
16
|
+
|
17
|
+
def result_message
|
18
|
+
if json_output?
|
19
|
+
created_environment_resource.response.raw_body
|
20
|
+
else
|
21
|
+
::Term::ANSIColor.green("Created #{params[:name]} environment in #{pact_broker_name} with UUID #{uuid}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def uuid
|
26
|
+
created_environment_resource.uuid
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|