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
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
require 'pact_broker/client'
|
3
|
+
require 'pact_broker/client/retry'
|
4
|
+
require 'pact_broker/client/pact_file'
|
5
|
+
require 'pact_broker/client/pact_hash'
|
6
|
+
require 'pact_broker/client/merge_pacts'
|
7
|
+
require 'pact_broker/client/hal_client_methods'
|
8
|
+
require 'pact_broker/client/hash_refinements'
|
9
|
+
require 'pact_broker/client/command_result'
|
10
|
+
|
11
|
+
module PactBroker
|
12
|
+
module Client
|
13
|
+
class PublishPactsTheOldWay
|
14
|
+
using PactBroker::Client::HashRefinements
|
15
|
+
include HalClientMethods
|
16
|
+
|
17
|
+
def self.call(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options={})
|
18
|
+
new(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options={}
|
22
|
+
@pact_broker_base_url = pact_broker_base_url
|
23
|
+
@pact_file_paths = pact_file_paths
|
24
|
+
@consumer_version_number = consumer_version_params[:number].respond_to?(:strip) ? consumer_version_params[:number].strip : consumer_version_params[:number]
|
25
|
+
@branch = consumer_version_params[:branch]
|
26
|
+
@build_url = consumer_version_params[:build_url]
|
27
|
+
@tags = consumer_version_params[:tags] ? consumer_version_params[:tags].collect{ |tag| tag.respond_to?(:strip) ? tag.strip : tag } : []
|
28
|
+
@version_required = consumer_version_params[:version_required]
|
29
|
+
@pact_broker_client_options = pact_broker_client_options
|
30
|
+
end
|
31
|
+
|
32
|
+
def call
|
33
|
+
validate
|
34
|
+
$stdout.puts("")
|
35
|
+
result = create_consumer_versions && apply_tags && publish_pacts
|
36
|
+
$stdout.puts("")
|
37
|
+
if result
|
38
|
+
PactBroker::Client::CommandResult.new(true)
|
39
|
+
else
|
40
|
+
PactBroker::Client::CommandResult.new(false, "One or more pacts failed to be published")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options, :version_required
|
47
|
+
|
48
|
+
def pact_broker_client
|
49
|
+
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
50
|
+
end
|
51
|
+
|
52
|
+
def index_entry_point
|
53
|
+
@index_entry_point ||= create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def index_resource
|
57
|
+
@index_resource ||= Retry.while_error do
|
58
|
+
index_entry_point.get!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def can_create_version_with_branch?
|
63
|
+
@can_create_version_with_branch ||= index_resource.can?('pb:pacticipant-version')
|
64
|
+
end
|
65
|
+
|
66
|
+
def merge_on_server?
|
67
|
+
pact_broker_client_options[:write] == :merge
|
68
|
+
end
|
69
|
+
|
70
|
+
def publish_pacts
|
71
|
+
pact_files.group_by(&:pact_name).collect do | pact_name, pact_files |
|
72
|
+
$stdout.puts "Merging #{pact_files.collect(&:path).join(", ")}" if pact_files.size > 1
|
73
|
+
publish_pact(PactHash[merge_contents(pact_files)])
|
74
|
+
end.all?
|
75
|
+
end
|
76
|
+
|
77
|
+
def merge_contents(pact_files)
|
78
|
+
MergePacts.call(pact_files.collect(&:pact_hash))
|
79
|
+
end
|
80
|
+
|
81
|
+
def pact_files
|
82
|
+
@pact_files ||= pact_file_paths.collect{ |pact_file_path| PactFile.new(pact_file_path) }
|
83
|
+
end
|
84
|
+
|
85
|
+
def consumer_names
|
86
|
+
pact_files.collect(&:consumer_name).uniq
|
87
|
+
end
|
88
|
+
|
89
|
+
def publish_pact pact
|
90
|
+
begin
|
91
|
+
$stdout.puts "Publishing #{pact.pact_name} to pact broker at #{pact_broker_base_url}"
|
92
|
+
publish_pact_contents pact
|
93
|
+
rescue => e
|
94
|
+
$stderr.puts "Failed to publish #{pact.pact_name} due to error: #{e.class} - #{e}"
|
95
|
+
false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_consumer_versions
|
100
|
+
if create_versions?
|
101
|
+
consumer_names.collect do | consumer_name |
|
102
|
+
create_version(index_resource, consumer_name)
|
103
|
+
end
|
104
|
+
true
|
105
|
+
else
|
106
|
+
true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_versions?
|
111
|
+
if version_required
|
112
|
+
if can_create_version_with_branch?
|
113
|
+
true
|
114
|
+
else
|
115
|
+
raise PactBroker::Client::Error.new("This version of the Pact Broker does not support versions with branches or build URLs. Please upgrade your broker to 2.76.2 or later.")
|
116
|
+
end
|
117
|
+
elsif (branch || build_url) && can_create_version_with_branch?
|
118
|
+
true
|
119
|
+
else
|
120
|
+
false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_version(index_resource, consumer_name)
|
125
|
+
Retry.while_error do
|
126
|
+
version_resource = index_resource._link('pb:pacticipant-version').expand(version: consumer_version_number, pacticipant: consumer_name).put(version_body).assert_success!
|
127
|
+
message = if version_resource.response.status == 200
|
128
|
+
"Replaced version #{consumer_version_number} of #{consumer_name}"
|
129
|
+
else
|
130
|
+
"Created version #{consumer_version_number} of #{consumer_name}"
|
131
|
+
end
|
132
|
+
|
133
|
+
message = message + " (branch #{branch})" if branch
|
134
|
+
$stdout.puts message
|
135
|
+
if version_resource.response.status == 200
|
136
|
+
$stdout.puts ::Term::ANSIColor.yellow("Replacing the version resource is not recommended under normal circumstances and may indicate that you have not configured your Pact pipeline correctly (unless you are just re-running a build for a particular commit). For more information see https://docs.pact.io/versioning")
|
137
|
+
end
|
138
|
+
true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def version_body
|
143
|
+
{
|
144
|
+
branch: branch,
|
145
|
+
buildUrl: build_url
|
146
|
+
}.compact
|
147
|
+
end
|
148
|
+
|
149
|
+
def apply_tags
|
150
|
+
return true if tags.empty?
|
151
|
+
tags.all? do | tag |
|
152
|
+
tag_consumer_version tag
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def tag_consumer_version tag
|
157
|
+
versions = pact_broker_client.pacticipants.versions
|
158
|
+
Retry.while_error do
|
159
|
+
consumer_names.collect do | consumer_name |
|
160
|
+
versions.tag(pacticipant: consumer_name, version: consumer_version_number, tag: tag)
|
161
|
+
$stdout.puts "Tagged version #{consumer_version_number} of #{consumer_name} as #{tag.inspect}"
|
162
|
+
true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
rescue => e
|
166
|
+
$stderr.puts "Failed to tag version due to error: #{e.class} - #{e}"
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
def publish_pact_contents(pact)
|
171
|
+
Retry.while_error do
|
172
|
+
pacts = pact_broker_client.pacticipants.versions.pacts
|
173
|
+
if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version_number)
|
174
|
+
if merge_on_server?
|
175
|
+
$stdout.puts "A pact for this consumer version is already published. Merging contents."
|
176
|
+
else
|
177
|
+
$stdout.puts ::Term::ANSIColor.yellow("A pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication. For more information, see https://docs.pact.io/versioning)")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
latest_pact_url = pacts.publish(pact_hash: pact, consumer_version: consumer_version_number)
|
182
|
+
$stdout.puts "The latest version of this pact can be accessed at the following URL:\n#{latest_pact_url}"
|
183
|
+
true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def validate
|
188
|
+
raise PactBroker::Client::Error.new("Please specify the consumer_version_number") unless (consumer_version_number && consumer_version_number.to_s.strip.size > 0)
|
189
|
+
raise PactBroker::Client::Error.new("Please specify the pact_broker_base_url") unless (pact_broker_base_url && pact_broker_base_url.to_s.strip.size > 0)
|
190
|
+
raise PactBroker::Client::Error.new("No pact files found") unless (pact_file_paths && pact_file_paths.any?)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module StringRefinements
|
4
|
+
refine NilClass do
|
5
|
+
def blank?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
refine String do
|
11
|
+
def not_blank?
|
12
|
+
!blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank?
|
16
|
+
self.strip.size == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
# ripped from rubyworks/facets, thank you
|
20
|
+
def snakecase
|
21
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
22
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
23
|
+
.tr('-', '_')
|
24
|
+
.gsub(/\s/, '_')
|
25
|
+
.gsub(/__+/, '_')
|
26
|
+
.downcase
|
27
|
+
end
|
28
|
+
|
29
|
+
# ripped from rubyworks/facets, thank you
|
30
|
+
def camelcase(*separators)
|
31
|
+
case separators.first
|
32
|
+
when Symbol, TrueClass, FalseClass, NilClass
|
33
|
+
first_letter = separators.shift
|
34
|
+
end
|
35
|
+
|
36
|
+
separators = ['_', '\s'] if separators.empty?
|
37
|
+
|
38
|
+
str = self.dup
|
39
|
+
|
40
|
+
separators.each do |s|
|
41
|
+
str = str.gsub(/(?:#{s}+)([a-z])/){ $1.upcase }
|
42
|
+
end
|
43
|
+
|
44
|
+
case first_letter
|
45
|
+
when :upper, true
|
46
|
+
str = str.gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase }
|
47
|
+
when :lower, false
|
48
|
+
str = str.gsub(/(\A|\s)([A-Z])/){ $1 + $2.downcase }
|
49
|
+
end
|
50
|
+
|
51
|
+
str
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -63,8 +63,9 @@ module PactBroker
|
|
63
63
|
pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
|
64
64
|
pact_broker_client_options.compact!
|
65
65
|
consumer_version_params = { number: consumer_version, branch: the_branch, build_url: build_url, tags: all_tags, version_required: version_required }.compact
|
66
|
-
|
67
|
-
|
66
|
+
result = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, {}, pact_broker_client_options).call
|
67
|
+
$stdout.puts result.message
|
68
|
+
raise "One or more pacts failed to be published" unless result.success
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
@@ -86,7 +87,6 @@ module PactBroker
|
|
86
87
|
branch
|
87
88
|
end
|
88
89
|
end
|
89
|
-
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -19,7 +19,7 @@ module PactBroker
|
|
19
19
|
@pacticipant_name = params.fetch(:pacticipant_name)
|
20
20
|
@version_number = params.fetch(:version_number)
|
21
21
|
@environment_name = params.fetch(:environment_name)
|
22
|
-
@
|
22
|
+
@target = params.fetch(:target)
|
23
23
|
@output = params.fetch(:output)
|
24
24
|
@pact_broker_client_options = pact_broker_client_options
|
25
25
|
end
|
@@ -36,7 +36,7 @@ module PactBroker
|
|
36
36
|
private
|
37
37
|
|
38
38
|
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
39
|
-
attr_reader :pacticipant_name, :version_number, :environment_name, :
|
39
|
+
attr_reader :pacticipant_name, :version_number, :environment_name, :target, :output
|
40
40
|
attr_reader :deployed_version_resource
|
41
41
|
|
42
42
|
def check_environment_exists
|
@@ -75,14 +75,14 @@ module PactBroker
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def record_deployment_request_body
|
78
|
-
{
|
78
|
+
{ target: target }
|
79
79
|
end
|
80
80
|
|
81
81
|
def result_message
|
82
82
|
if output == "text"
|
83
|
-
message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name}
|
84
|
-
|
85
|
-
message
|
83
|
+
message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name}"
|
84
|
+
message = "#{message} (target #{target})" if target
|
85
|
+
"#{message} in #{pact_broker_name}."
|
86
86
|
elsif output == "json"
|
87
87
|
deployed_version_resource.response.raw_body
|
88
88
|
else
|
@@ -2,6 +2,10 @@ require 'pact_broker/client/hal_client_methods'
|
|
2
2
|
require 'pact_broker/client/error'
|
3
3
|
require 'pact_broker/client/command_result'
|
4
4
|
|
5
|
+
# TODO
|
6
|
+
# --limit 1
|
7
|
+
# order by date so that the oldest one gets undeployed first
|
8
|
+
|
5
9
|
module PactBroker
|
6
10
|
module Client
|
7
11
|
class Versions
|
@@ -24,10 +28,17 @@ module PactBroker
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def call
|
27
|
-
|
28
|
-
|
31
|
+
check_if_command_supported
|
32
|
+
if deployed_version_links_for_environment.any?
|
33
|
+
@undeployment_entities = deployed_version_links_for_environment.collect do | deployed_version_link |
|
34
|
+
deployed_version_link.get!._link!("pb:record-undeployment").post!
|
35
|
+
end
|
36
|
+
else
|
37
|
+
check_environment_exists
|
38
|
+
raise_not_found_error
|
39
|
+
end
|
29
40
|
|
30
|
-
PactBroker::Client::CommandResult.new(true,
|
41
|
+
PactBroker::Client::CommandResult.new(true, "foo")
|
31
42
|
rescue PactBroker::Client::Error => e
|
32
43
|
PactBroker::Client::CommandResult.new(false, e.message)
|
33
44
|
end
|
@@ -35,83 +46,49 @@ module PactBroker
|
|
35
46
|
private
|
36
47
|
|
37
48
|
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
38
|
-
attr_reader :pacticipant_name, :version_number, :environment_name, :
|
39
|
-
attr_reader :deployed_version_resource
|
49
|
+
attr_reader :pacticipant_name, :version_number, :environment_name, :target, :output
|
50
|
+
attr_reader :deployed_version_resource, :undeployment_entities
|
40
51
|
|
41
|
-
def
|
42
|
-
|
43
|
-
.get(version: version_number)
|
44
|
-
.embedded_entities("deployedVersions")
|
45
|
-
deployed_versions
|
52
|
+
def version_resource
|
53
|
+
index_resource._link!("pb:pacticipant-version").expand(pacticipant: pacticipant_name, version: version_number).get!
|
46
54
|
end
|
47
55
|
|
48
|
-
def
|
49
|
-
@
|
50
|
-
._link!("pb:environments")
|
51
|
-
.get!(name: environment_name)
|
52
|
-
.embedded_entities("environments")
|
53
|
-
.tap { |it| raise "Environment not found '#{environment_name}'" if it.empty? }
|
54
|
-
.first
|
55
|
-
._link!("pb:currently-deployed-versions-for-pacticipant")
|
56
|
-
.expand(pacticipant: pacticipant_name)
|
56
|
+
def deployed_version_links
|
57
|
+
@deployed_version_links ||= version_resource._links!("pb:currently-deployed-versions")
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
-
@
|
61
|
-
.get(version: version_number)
|
62
|
-
.embedded_entities("deployedVersions")
|
60
|
+
def deployed_version_links_for_environment
|
61
|
+
@deployed_version_links_for_environment ||= deployed_version_links.select(environment_name)
|
63
62
|
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# def get_record_deployment_relation
|
73
|
-
# record_deployment_links = get_pacticipant_version._links!("pb:record-deployment")
|
74
|
-
# link_for_environment = record_deployment_links.find(environment_name)
|
75
|
-
# if link_for_environment
|
76
|
-
# link_for_environment
|
77
|
-
# else
|
78
|
-
# check_environment_exists
|
79
|
-
# # Force the exception to be raised
|
80
|
-
# record_deployment_links.find!(environment_name, "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}.")
|
81
|
-
# end
|
82
|
-
# end
|
83
|
-
|
84
|
-
# def get_pacticipant_version
|
85
|
-
# index_resource
|
86
|
-
# ._link!("pb:pacticipant-version")
|
87
|
-
# .expand(pacticipant: pacticipant_name, version: version_number)
|
88
|
-
# .get
|
89
|
-
# .assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
|
90
|
-
# end
|
91
|
-
|
92
|
-
# def record_deployment_request_body
|
93
|
-
# { replacedPreviousDeployedVersion: replaced_previous_deployed_version }
|
94
|
-
# end
|
64
|
+
def check_environment_exists
|
65
|
+
index_resource
|
66
|
+
._link!("pb:environments")
|
67
|
+
.get!
|
68
|
+
._links("pb:environments")
|
69
|
+
.find!(environment_name, "No environment found with name '#{environment_name}'")
|
70
|
+
end
|
95
71
|
|
96
|
-
def
|
97
|
-
|
98
|
-
# if output == "text"
|
99
|
-
# message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name} in #{pact_broker_name}."
|
100
|
-
# suffix = replaced_previous_deployed_version ? " Marked previous deployed version as undeployed." : ""
|
101
|
-
# message + suffix
|
102
|
-
# elsif output == "json"
|
103
|
-
# deployed_version_resource.response.raw_body
|
104
|
-
# else
|
105
|
-
# ""
|
106
|
-
# end
|
72
|
+
def raise_not_found_error
|
73
|
+
raise PactBroker::Client::Error.new(deployed_version_not_found_message)
|
107
74
|
end
|
108
75
|
|
109
|
-
def
|
110
|
-
|
76
|
+
def deployed_version_not_found_message
|
77
|
+
if (env_names = deployed_version_links.names).any?
|
78
|
+
"#{pacticipant_name} version #{version_number} is not currently deployed to #{environment_name}. It is currently deployed to: #{env_names.join(", ")}"
|
79
|
+
else
|
80
|
+
"#{pacticipant_name} version #{version_number} is not currently deployed to any environment."
|
81
|
+
end
|
111
82
|
end
|
112
83
|
|
113
|
-
def
|
114
|
-
|
84
|
+
def result_message
|
85
|
+
if output == "text"
|
86
|
+
message = "Recorded undeployment of #{pacticipant_name} version #{version_number} from #{environment_name} in #{pact_broker_name}."
|
87
|
+
elsif output == "json"
|
88
|
+
undeployment_entities.last.response.raw_body
|
89
|
+
else
|
90
|
+
""
|
91
|
+
end
|
115
92
|
end
|
116
93
|
|
117
94
|
def check_if_command_supported
|