pact_broker-client 1.44.0 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +5 -9
- data/lib/pact_broker/client/base_command.rb +3 -0
- data/lib/pact_broker/client/can_i_deploy.rb +40 -5
- data/lib/pact_broker/client/cli/broker.rb +3 -1
- data/lib/pact_broker/client/cli/deployment_commands.rb +25 -5
- data/lib/pact_broker/client/deployments.rb +4 -4
- data/lib/pact_broker/client/deployments/record_support_ended.rb +103 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +42 -35
- data/lib/pact_broker/client/hal/entity.rb +17 -2
- data/lib/pact_broker/client/pacticipants/create.rb +1 -1
- data/lib/pact_broker/client/version.rb +1 -1
- data/script/record-deployments-and-releases.sh +11 -3
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +7 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +62 -2
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +15 -2
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +208 -0
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +219 -0
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
- data/spec/service_providers/record_release_spec.rb +1 -4
- data/spec/service_providers/record_undeployment_spec.rb +166 -0
- data/spec/support/shared_context.rb +2 -1
- data/tasks/pact.rake +8 -6
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a06a67fbe9da6f970649c5159443669ed9ce419911e6178594944467255dd0
|
4
|
+
data.tar.gz: c45dcfa2fd158febe01b9094e2125b4a1637c716da3a6d11d3bd13a8ce19867c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6da2ec04fc73a54ae53bebc62ddb5ddfe1fe1db17b1f94d22a3e195edfb756ad6330e9a99ebfeb1a6f5d20be71c92df4c16c0a808a409623b9600fb59e2e6385
|
7
|
+
data.tar.gz: c714b39a69e0f96ffccabe9b6bc3097c0401a6c1931a0de89e57eae7c1e0c04ef5133e1c3d124df49b2dd294bdd90fe2415baeba365e1bf44fc40b45b4602164
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
<a name="v1.45.0"></a>
|
2
|
+
### v1.45.0 (2021-06-16)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* **can-i-deploy**
|
7
|
+
* allow dry-run to be enabled by setting ACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true ([0562436](/../../commit/0562436))
|
8
|
+
* add --dry-run option ([9d90c79](/../../commit/9d90c79))
|
9
|
+
|
10
|
+
* add record-support-ended (feature toggled off) ([8f6b593](/../../commit/8f6b593))
|
11
|
+
* update record-undeployment (feature toggled off) ([0c0dd15](/../../commit/0c0dd15))
|
12
|
+
* update record-undeployment (feature toggled off) ([93046d5](/../../commit/93046d5))
|
13
|
+
|
1
14
|
<a name="v1.44.0"></a>
|
2
15
|
### v1.44.0 (2021-06-09)
|
3
16
|
|
data/README.md
CHANGED
@@ -84,7 +84,8 @@ Options:
|
|
84
84
|
# The pacticipant version. Must be entered after the --pacticipant that it relates to.
|
85
85
|
[--ignore=IGNORE]
|
86
86
|
# The pacticipant name to ignore. Use once for each pacticipant being ignored.
|
87
|
-
A specific version can be ignored by also specifying a --version after the
|
87
|
+
A specific version can be ignored by also specifying a --version after the
|
88
|
+
pacticipant name option.
|
88
89
|
-l, [--latest=[TAG]]
|
89
90
|
# Use the latest pacticipant version. Optionally specify a TAG to use the
|
90
91
|
latest version with the specified tag.
|
@@ -103,6 +104,9 @@ Options:
|
|
103
104
|
# The time between retries in seconds. Use in conjuction with --retry-while-unknown
|
104
105
|
|
105
106
|
# Default: 10
|
107
|
+
[--dry-run], [--no-dry-run]
|
108
|
+
# When enabled, always exits process with a success code. Can also be enabled by setting
|
109
|
+
the environment variable PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true.
|
106
110
|
-b, --broker-base-url=BROKER_BASE_URL
|
107
111
|
# The base URL of the Pact Broker
|
108
112
|
-u, [--broker-username=BROKER_USERNAME]
|
@@ -113,14 +117,6 @@ Options:
|
|
113
117
|
# Pact Broker bearer token
|
114
118
|
-v, [--verbose], [--no-verbose]
|
115
119
|
# Verbose output. Default: false
|
116
|
-
|
117
|
-
Description:
|
118
|
-
Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are
|
119
|
-
compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any
|
120
|
-
missing or failed verification results.
|
121
|
-
|
122
|
-
The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD may be used
|
123
|
-
instead of their respective command line options.
|
124
120
|
```
|
125
121
|
|
126
122
|
Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any missing or failed verification results.
|
@@ -65,6 +65,9 @@ module PactBroker
|
|
65
65
|
{ error: error_hash }.to_json
|
66
66
|
end
|
67
67
|
|
68
|
+
def error_message_as_json(message)
|
69
|
+
{ error: { message: message } }.to_json
|
70
|
+
end
|
68
71
|
|
69
72
|
def text_error_message(e, include_backtrace)
|
70
73
|
maybe_backtrace = (include_backtrace ? "\n" + e.backtrace.join("\n") : "")
|
@@ -33,9 +33,9 @@ module PactBroker
|
|
33
33
|
def call
|
34
34
|
create_result(fetch_matrix_with_retries)
|
35
35
|
rescue PactBroker::Client::Error => e
|
36
|
-
Result.new(
|
36
|
+
Result.new(dry_run_or_false, for_dry_run(Term::ANSIColor.red(e.message)))
|
37
37
|
rescue StandardError => e
|
38
|
-
Result.new(
|
38
|
+
Result.new(dry_run_or_false, for_dry_run(Term::ANSIColor.red("Error retrieving matrix. #{e.class} - #{e.message}") + "\n#{e.backtrace.join("\n")}"))
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -46,14 +46,15 @@ module PactBroker
|
|
46
46
|
if matrix.deployable?
|
47
47
|
Result.new(true, success_message(matrix))
|
48
48
|
else
|
49
|
-
Result.new(
|
49
|
+
Result.new(dry_run_or_false, failure_message(matrix))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def success_message(matrix)
|
54
54
|
message = format_matrix(matrix)
|
55
55
|
if format != 'json'
|
56
|
-
message = warning(matrix) +
|
56
|
+
message = warning(matrix) + computer_says(true) + message + "\n\n" + notice_or_reason(matrix, :green)
|
57
|
+
message = for_dry_run(message)
|
57
58
|
end
|
58
59
|
message
|
59
60
|
end
|
@@ -61,11 +62,28 @@ module PactBroker
|
|
61
62
|
def failure_message(matrix)
|
62
63
|
message = format_matrix(matrix)
|
63
64
|
if format != 'json'
|
64
|
-
message = warning(matrix) +
|
65
|
+
message = warning(matrix) + computer_says(false) + message + "\n\n" + notice_or_reason(matrix, :red)
|
66
|
+
message = for_dry_run(message)
|
65
67
|
end
|
66
68
|
message
|
67
69
|
end
|
68
70
|
|
71
|
+
def computer_says(success)
|
72
|
+
if success
|
73
|
+
if dry_run?
|
74
|
+
"Computer says yes \\o/ (and maybe you don't need to enable dry run)"
|
75
|
+
else
|
76
|
+
Term::ANSIColor.green('Computer says yes \o/ ')
|
77
|
+
end
|
78
|
+
else
|
79
|
+
if dry_run?
|
80
|
+
"Computer says no ¯\\_(ツ)_/¯ (but you're ignoring this by enabling dry run)"
|
81
|
+
else
|
82
|
+
Term::ANSIColor.red("Computer says no ¯\_(ツ)_/¯")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
69
87
|
def notice_or_reason(matrix, reason_color)
|
70
88
|
if matrix.notices
|
71
89
|
PactBroker::Client::ColorizeNotices.call(matrix.notices).join("\n")
|
@@ -114,6 +132,23 @@ module PactBroker
|
|
114
132
|
options[:retry_while_unknown] > 0
|
115
133
|
end
|
116
134
|
|
135
|
+
def dry_run?
|
136
|
+
options[:dry_run]
|
137
|
+
end
|
138
|
+
|
139
|
+
def dry_run_or_false
|
140
|
+
dry_run? || false
|
141
|
+
end
|
142
|
+
|
143
|
+
def for_dry_run(lines)
|
144
|
+
if dry_run?
|
145
|
+
prefix = Term::ANSIColor.yellow("[dry-run] ")
|
146
|
+
lines.split("\n").collect { |line| prefix + Term::ANSIColor.uncolor(line) }.join("\n") + "\n" + prefix + "\n" + prefix + Term::ANSIColor.green("Dry run enabled - ignoring any failures")
|
147
|
+
else
|
148
|
+
lines
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
117
152
|
def retry_options
|
118
153
|
{
|
119
154
|
condition: lambda { |matrix| !matrix.any_unknown? },
|
@@ -37,6 +37,7 @@ module PactBroker
|
|
37
37
|
method_option :retry_interval, banner: 'SECONDS', type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
|
38
38
|
# Allow limit to be set manually until https://github.com/pact-foundation/pact_broker-client/issues/53 is fixed
|
39
39
|
method_option :limit, hide: true
|
40
|
+
method_option :dry_run, type: :boolean, default: false, desc: "When dry-run is enabled, always exit process with a success code. Can also be enabled by setting the environment variable PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true."
|
40
41
|
shared_authentication_options
|
41
42
|
|
42
43
|
def can_i_deploy(*ignored_but_necessary)
|
@@ -51,7 +52,8 @@ module PactBroker
|
|
51
52
|
[]
|
52
53
|
end
|
53
54
|
validate_can_i_deploy_selectors(selectors)
|
54
|
-
|
55
|
+
dry_run = options.dry_run || ENV["PACT_BROKER_CAN_I_DEPLOY_DRY_RUN"] == "true"
|
56
|
+
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval, dry_run: dry_run }
|
55
57
|
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)
|
56
58
|
$stdout.puts result.message
|
57
59
|
$stdout.flush
|
@@ -2,11 +2,15 @@ module PactBroker
|
|
2
2
|
module Client
|
3
3
|
module CLI
|
4
4
|
module DeploymentCommands
|
5
|
-
|
5
|
+
RECORD_DEPLOYMENT_HELP_URL = "https://docs.pact.io/go/record-deployment"
|
6
|
+
RECORD_UNDEPLOYMENT_HELP_URL = "https://docs.pact.io/go/record-undeployment"
|
7
|
+
RECORD_RELEASE_HELP_URL = "https://docs.pact.io/go/record-release"
|
8
|
+
RECORD_SUPPORT_ENDED_HELP_URL = "https://docs.pact.io/go/record-support-ended"
|
9
|
+
|
6
10
|
|
7
11
|
def self.included(thor)
|
8
12
|
thor.class_eval do
|
9
|
-
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See #{
|
13
|
+
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See #{RECORD_DEPLOYMENT_HELP_URL} for more information."
|
10
14
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
11
15
|
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
12
16
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
@@ -24,8 +28,8 @@ module PactBroker
|
|
24
28
|
execute_deployment_command(params, "RecordDeployment")
|
25
29
|
end
|
26
30
|
|
27
|
-
desc "record-undeployment", "Record undeployment of a pacticipant
|
28
|
-
long_desc "Note that use of this command is not required if you are deploying over a previous version, as record-deployment will
|
31
|
+
desc "record-undeployment", "Record undeployment of a pacticipant from an environment."
|
32
|
+
long_desc "Note that use of this command is only required if you are permanently removing an application instance from an environment. It is not required if you are deploying over a previous version, as record-deployment will automatically mark the previously deployed version as undeployed for you. See #{RECORD_UNDEPLOYMENT_HELP_URL} for more information."
|
29
33
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was undeployed."
|
30
34
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was undeployed from."
|
31
35
|
method_option :target, default: nil, required: false, desc: "Optional. The target that the application is being undeployed from - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
|
@@ -41,7 +45,7 @@ module PactBroker
|
|
41
45
|
execute_deployment_command(params, "RecordUndeployment")
|
42
46
|
end
|
43
47
|
|
44
|
-
desc "record-release", "Record release of a pacticipant version to an environment. See See #{
|
48
|
+
desc "record-release", "Record release of a pacticipant version to an environment. See See #{RECORD_RELEASE_HELP_URL} for more information."
|
45
49
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was released."
|
46
50
|
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was released."
|
47
51
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was released to."
|
@@ -57,6 +61,22 @@ module PactBroker
|
|
57
61
|
execute_deployment_command(params, "RecordRelease")
|
58
62
|
end
|
59
63
|
|
64
|
+
desc "record-support-ended", "Record the end of support for a pacticipant version in an environment. See #{RECORD_SUPPORT_ENDED_HELP_URL} for more information."
|
65
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant."
|
66
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number for which support is ended."
|
67
|
+
method_option :environment, required: true, desc: "The name of the environment in which the support is ended."
|
68
|
+
output_option_json_or_text
|
69
|
+
shared_authentication_options
|
70
|
+
|
71
|
+
def record_support_ended
|
72
|
+
params = {
|
73
|
+
pacticipant_name: options.pacticipant,
|
74
|
+
version_number: options.version,
|
75
|
+
environment_name: options.environment
|
76
|
+
}
|
77
|
+
execute_deployment_command(params, "RecordSupportEnded")
|
78
|
+
end
|
79
|
+
|
60
80
|
no_commands do
|
61
81
|
def execute_deployment_command(params, command_class_name)
|
62
82
|
require 'pact_broker/client/deployments'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
1
|
+
require "pact_broker/client/deployments/record_deployment"
|
2
|
+
require "pact_broker/client/deployments/record_release"
|
3
|
+
require "pact_broker/client/deployments/record_undeployment"
|
4
|
+
require "pact_broker/client/deployments/record_support_ended"
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'pact_broker/client/base_command'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Deployments
|
6
|
+
class RecordSupportEnded < PactBroker::Client::BaseCommand
|
7
|
+
def initialize(params, options, pact_broker_client_options)
|
8
|
+
super
|
9
|
+
@pacticipant_name = params.fetch(:pacticipant_name)
|
10
|
+
@environment_name = params.fetch(:environment_name)
|
11
|
+
@version_number = params.fetch(:version_number)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def do_call
|
17
|
+
if unsupported_versions_resources.empty?
|
18
|
+
PactBroker::Client::CommandResult.new(false, error_result_message)
|
19
|
+
else
|
20
|
+
PactBroker::Client::CommandResult.new(unsupported_versions_resources.all?(&:success?), result_message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :pacticipant_name, :environment_name, :version_number
|
25
|
+
|
26
|
+
def currently_supported_versions_link
|
27
|
+
environment_resource._link("pb:currently-supported-versions") or raise PactBroker::Client::Error.new(not_supported_message)
|
28
|
+
end
|
29
|
+
|
30
|
+
def currently_supported_version_entities_for_pacticipant_version
|
31
|
+
@deployed_version_links ||= currently_supported_versions_link.get!(pacticipant: pacticipant_name, version: version_number).embedded_entities!("releasedVersions")
|
32
|
+
end
|
33
|
+
|
34
|
+
def unsupported_versions_resources
|
35
|
+
@unsupported_versions_resources ||= currently_supported_version_entities_for_pacticipant_version.collect do | entity |
|
36
|
+
entity._link!("self").patch(currentlySupported: false)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def action
|
41
|
+
"undeployment"
|
42
|
+
end
|
43
|
+
|
44
|
+
def environment_resource
|
45
|
+
index_resource
|
46
|
+
._link!("pb:environments")
|
47
|
+
.get!
|
48
|
+
._links("pb:environments")
|
49
|
+
.find!(environment_name, "No environment found with name '#{environment_name}'")
|
50
|
+
.get!
|
51
|
+
end
|
52
|
+
|
53
|
+
def result_message
|
54
|
+
if json_output?
|
55
|
+
unsupported_versions_resources.collect{ | resource | resource.response.body }.to_a.to_json
|
56
|
+
else
|
57
|
+
unsupported_versions_resources.collect do | undeployed_versions_resource |
|
58
|
+
if undeployed_versions_resource.success?
|
59
|
+
green("#{success_result_text_message(undeployed_versions_resource)} in #{pact_broker_name}.")
|
60
|
+
else
|
61
|
+
red(undeployed_versions_resource.error_message)
|
62
|
+
end
|
63
|
+
end.join("\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def success_result_text_message(undeployed_versions_resource)
|
68
|
+
"Recorded support ended for #{pacticipant_name} version #{version_number} in #{environment_name} environment"
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_result_message
|
72
|
+
if json_output?
|
73
|
+
error_message_as_json(error_text)
|
74
|
+
else
|
75
|
+
red(error_text)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def error_text
|
80
|
+
if pacticipant_does_not_exist?
|
81
|
+
"No pacticipant with name '#{pacticipant_name}' found."
|
82
|
+
else
|
83
|
+
"#{pacticipant_name} version #{version_number} is not currently released in #{environment_name} environment. Cannot record support ended."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def not_supported_message
|
88
|
+
"This version of the Pact Broker does not support recording end of support. Please upgrade to version 2.80.0 or later."
|
89
|
+
end
|
90
|
+
|
91
|
+
def pacticipant_does_not_exist?
|
92
|
+
index_resource._link("pb:pacticipant") && index_resource._link("pb:pacticipant").expand(pacticipant: pacticipant_name).get.does_not_exist?
|
93
|
+
end
|
94
|
+
|
95
|
+
def check_if_command_supported
|
96
|
+
unless index_resource.can?("pb:environments")
|
97
|
+
raise PactBroker::Client::Error.new(not_supported_message)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -4,10 +4,7 @@ module PactBroker
|
|
4
4
|
module Client
|
5
5
|
module Deployments
|
6
6
|
class RecordUndeployment < PactBroker::Client::BaseCommand
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
7
|
+
def initialize(params, options, pact_broker_client_options)
|
11
8
|
super
|
12
9
|
@pacticipant_name = params.fetch(:pacticipant_name)
|
13
10
|
@environment_name = params.fetch(:environment_name)
|
@@ -18,26 +15,30 @@ module PactBroker
|
|
18
15
|
|
19
16
|
def do_call
|
20
17
|
if undeployed_versions_resources.empty?
|
21
|
-
|
22
|
-
PactBroker::Client::CommandResult.new(false, deployed_version_not_found_error_message)
|
18
|
+
PactBroker::Client::CommandResult.new(false, error_result_message)
|
23
19
|
else
|
24
|
-
PactBroker::Client::CommandResult.new(undeployed_versions_resources.all?(
|
20
|
+
PactBroker::Client::CommandResult.new(undeployed_versions_resources.all?(&:success?), result_message)
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
|
-
attr_reader :pacticipant_name, :
|
29
|
-
attr_reader :deployed_version_resource, :undeployment_entities
|
24
|
+
attr_reader :pacticipant_name, :environment_name, :target
|
30
25
|
|
31
26
|
def currently_deployed_versions_link
|
32
27
|
environment_resource._link("pb:currently-deployed-versions") or raise PactBroker::Client::Error.new(not_supported_message)
|
33
28
|
end
|
34
29
|
|
35
|
-
def
|
36
|
-
@deployed_version_links ||= currently_deployed_versions_link.get!(pacticipant: pacticipant_name
|
30
|
+
def currently_deployed_version_entities_for_pacticipant
|
31
|
+
@deployed_version_links ||= currently_deployed_versions_link.get!(pacticipant: pacticipant_name).embedded_entities!("deployedVersions")
|
32
|
+
end
|
33
|
+
|
34
|
+
def currently_deployed_version_entities_for_pacticipant_and_target
|
35
|
+
currently_deployed_version_entities_for_pacticipant.select do | entity |
|
36
|
+
entity.target == target
|
37
|
+
end
|
37
38
|
end
|
38
39
|
|
39
40
|
def undeployed_versions_resources
|
40
|
-
@undeployed_versions_resources ||=
|
41
|
+
@undeployed_versions_resources ||= currently_deployed_version_entities_for_pacticipant_and_target.collect do | entity |
|
41
42
|
entity._link!("self").patch(currentlyDeployed: false)
|
42
43
|
end
|
43
44
|
end
|
@@ -55,12 +56,6 @@ module PactBroker
|
|
55
56
|
.get!
|
56
57
|
end
|
57
58
|
|
58
|
-
def check_pacticipant_exists!
|
59
|
-
if index_resource._link!("pb:pacticipant").expand(pacticipant: pacticipant_name).get.does_not_exist?
|
60
|
-
raise PactBroker::Client::Error.new("No pacticipant with name '#{pacticipant_name}' found")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
59
|
def result_message
|
65
60
|
if json_output?
|
66
61
|
undeployed_versions_resources.collect{ | resource | resource.response.body }.to_a.to_json
|
@@ -76,32 +71,40 @@ module PactBroker
|
|
76
71
|
end
|
77
72
|
|
78
73
|
def success_result_text_message(undeployed_versions_resource)
|
79
|
-
|
80
|
-
message = "Recorded #{action} of #{pacticipant_name}
|
81
|
-
if
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
74
|
+
version = undeployed_versions_resource.embedded_entity{ | embedded_entity| embedded_entity && embedded_entity['version'] }
|
75
|
+
message = "Recorded #{action} of #{pacticipant_name}"
|
76
|
+
message = "#{message} version #{version.number}" if (version && version.number)
|
77
|
+
message = "#{message} from #{environment_name} environment"
|
78
|
+
message = "#{message} (target #{target})" if target
|
79
|
+
message
|
86
80
|
end
|
87
81
|
|
88
|
-
def
|
89
|
-
target_bit = target ? " with target '#{target}'" : ""
|
90
|
-
message = "#{pacticipant_name} is not currently deployed to #{environment_name}#{target_bit}. Cannot record undeployment."
|
91
|
-
|
82
|
+
def error_result_message
|
92
83
|
if json_output?
|
93
|
-
|
84
|
+
error_message_as_json(error_text)
|
94
85
|
else
|
95
|
-
red(
|
86
|
+
red(error_text)
|
96
87
|
end
|
97
88
|
end
|
98
89
|
|
90
|
+
def error_text
|
91
|
+
if pacticipant_does_not_exist?
|
92
|
+
"No pacticipant with name '#{pacticipant_name}' found."
|
93
|
+
else
|
94
|
+
if currently_deployed_version_entities_for_pacticipant.any?
|
95
|
+
target_does_not_match_message
|
96
|
+
else
|
97
|
+
"#{pacticipant_name} is not currently deployed to #{environment_name} environment. Cannot record undeployment."
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
99
101
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
102
|
+
def target_does_not_match_message
|
103
|
+
potential_targets = currently_deployed_version_entities_for_pacticipant.collect(&:target).collect { |target| target || "<no target>"}
|
104
|
+
if target
|
105
|
+
"#{pacticipant_name} is not currently deployed to target '#{target}' in #{environment_name} environment. Please specify one of the following targets to record the undeployment from: #{potential_targets.join(", ")}"
|
103
106
|
else
|
104
|
-
"
|
107
|
+
"Please specify one of the following targets to record the undeployment from: #{potential_targets.join(", ")}"
|
105
108
|
end
|
106
109
|
end
|
107
110
|
|
@@ -109,6 +112,10 @@ module PactBroker
|
|
109
112
|
"This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
|
110
113
|
end
|
111
114
|
|
115
|
+
def pacticipant_does_not_exist?
|
116
|
+
index_resource._link("pb:pacticipant") && index_resource._link("pb:pacticipant").expand(pacticipant: pacticipant_name).get.does_not_exist?
|
117
|
+
end
|
118
|
+
|
112
119
|
def check_if_command_supported
|
113
120
|
unless index_resource.can?("pb:environments")
|
114
121
|
raise PactBroker::Client::Error.new(not_supported_message)
|