pact_broker-client 1.35.0 → 1.38.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -0
- data/CHANGELOG.md +34 -0
- data/Rakefile +2 -0
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +283 -0
- data/lib/pact_broker/client.rb +1 -1
- data/lib/pact_broker/client/backports.rb +13 -0
- data/lib/pact_broker/client/cli/broker.rb +112 -34
- data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
- data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
- data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
- data/lib/pact_broker/client/cli/custom_thor.rb +11 -17
- data/lib/pact_broker/client/git.rb +43 -22
- data/lib/pact_broker/client/hal/entity.rb +44 -3
- data/lib/pact_broker/client/hal/http_client.rb +5 -1
- data/lib/pact_broker/client/hal/links.rb +39 -0
- data/lib/pact_broker/client/hal_client_methods.rb +11 -0
- data/lib/pact_broker/client/hash_refinements.rb +19 -0
- data/lib/pact_broker/client/matrix.rb +2 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +2 -0
- data/lib/pact_broker/client/publish_pacts.rb +85 -14
- data/lib/pact_broker/client/tasks/publication_task.rb +37 -6
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/record_deployment.rb +109 -0
- data/lib/pact_broker/client/versions/record_undeployment.rb +125 -0
- data/pact-broker-client.gemspec +1 -1
- data/script/publish-pact.sh +7 -1
- data/script/record-deployment.sh +4 -0
- data/script/trigger-release.sh +1 -1
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +51 -6
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +1 -7
- data/spec/lib/pact_broker/client/git_spec.rb +39 -2
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +4 -3
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +99 -6
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
- data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
- data/spec/pacts/pact_broker_client-pact_broker.json +287 -0
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
- data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
- data/spec/service_providers/record_deployment_spec.rb +219 -0
- data/spec/spec_helper.rb +2 -0
- data/tasks/pact.rake +2 -0
- metadata +19 -7
@@ -4,39 +4,60 @@ require 'pact_broker/client/retry'
|
|
4
4
|
require 'pact_broker/client/pact_file'
|
5
5
|
require 'pact_broker/client/pact_hash'
|
6
6
|
require 'pact_broker/client/merge_pacts'
|
7
|
+
require 'pact_broker/client/hal_client_methods'
|
8
|
+
require 'pact_broker/client/hash_refinements'
|
7
9
|
|
8
10
|
module PactBroker
|
9
11
|
module Client
|
10
12
|
class PublishPacts
|
13
|
+
using PactBroker::Client::HashRefinements
|
14
|
+
include HalClientMethods
|
11
15
|
|
12
|
-
def self.call(pact_broker_base_url, pact_file_paths,
|
13
|
-
new(pact_broker_base_url, pact_file_paths,
|
16
|
+
def self.call(pact_broker_base_url, pact_file_paths, consumer_version_params, pact_broker_client_options={})
|
17
|
+
new(pact_broker_base_url, pact_file_paths, consumer_version_params, pact_broker_client_options).call
|
14
18
|
end
|
15
19
|
|
16
|
-
def initialize pact_broker_base_url, pact_file_paths,
|
20
|
+
def initialize pact_broker_base_url, pact_file_paths, consumer_version_params, pact_broker_client_options={}
|
17
21
|
@pact_broker_base_url = pact_broker_base_url
|
18
22
|
@pact_file_paths = pact_file_paths
|
19
|
-
@
|
20
|
-
@
|
23
|
+
@consumer_version_number = consumer_version_params[:number].respond_to?(:strip) ? consumer_version_params[:number].strip : consumer_version_params[:number]
|
24
|
+
@branch = consumer_version_params[:branch]
|
25
|
+
@build_url = consumer_version_params[:build_url]
|
26
|
+
@tags = consumer_version_params[:tags] ? consumer_version_params[:tags].collect{ |tag| tag.respond_to?(:strip) ? tag.strip : tag } : []
|
27
|
+
@version_required = consumer_version_params[:version_required]
|
21
28
|
@pact_broker_client_options = pact_broker_client_options
|
22
29
|
end
|
23
30
|
|
24
31
|
def call
|
25
32
|
validate
|
26
33
|
$stdout.puts("")
|
27
|
-
result = apply_tags && publish_pacts
|
34
|
+
result = create_consumer_versions && apply_tags && publish_pacts
|
28
35
|
$stdout.puts("")
|
29
36
|
result
|
30
37
|
end
|
31
38
|
|
32
39
|
private
|
33
40
|
|
34
|
-
attr_reader :pact_broker_base_url, :pact_file_paths, :
|
41
|
+
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options, :version_required
|
35
42
|
|
36
43
|
def pact_broker_client
|
37
44
|
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
38
45
|
end
|
39
46
|
|
47
|
+
def index_entry_point
|
48
|
+
@index_entry_point ||= create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def index_resource
|
52
|
+
@index_resource ||= Retry.while_error do
|
53
|
+
index_entry_point.get!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def can_create_version_with_branch?
|
58
|
+
@can_create_version_with_branch ||= index_resource.can?('pb:pacticipant-version')
|
59
|
+
end
|
60
|
+
|
40
61
|
def merge_on_server?
|
41
62
|
pact_broker_client_options[:write] == :merge
|
42
63
|
end
|
@@ -70,8 +91,58 @@ module PactBroker
|
|
70
91
|
end
|
71
92
|
end
|
72
93
|
|
94
|
+
def create_consumer_versions
|
95
|
+
if create_versions?
|
96
|
+
consumer_names.collect do | consumer_name |
|
97
|
+
create_version(index_resource, consumer_name)
|
98
|
+
end
|
99
|
+
true
|
100
|
+
else
|
101
|
+
true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_versions?
|
106
|
+
if version_required
|
107
|
+
if can_create_version_with_branch?
|
108
|
+
true
|
109
|
+
else
|
110
|
+
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.")
|
111
|
+
end
|
112
|
+
elsif (branch || build_url) && can_create_version_with_branch?
|
113
|
+
true
|
114
|
+
else
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def create_version(index_resource, consumer_name)
|
120
|
+
Retry.while_error do
|
121
|
+
version_resource = index_resource._link('pb:pacticipant-version').expand(version: consumer_version_number, pacticipant: consumer_name).put(version_body).assert_success!
|
122
|
+
message = if version_resource.response.status == 200
|
123
|
+
"Replaced version #{consumer_version_number} of #{consumer_name}"
|
124
|
+
else
|
125
|
+
"Created version #{consumer_version_number} of #{consumer_name}"
|
126
|
+
end
|
127
|
+
|
128
|
+
message = message + " (branch #{branch})" if branch
|
129
|
+
$stdout.puts message
|
130
|
+
if version_resource.response.status == 200
|
131
|
+
$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")
|
132
|
+
end
|
133
|
+
true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def version_body
|
138
|
+
{
|
139
|
+
branch: branch,
|
140
|
+
buildUrl: build_url
|
141
|
+
}.compact
|
142
|
+
end
|
143
|
+
|
73
144
|
def apply_tags
|
74
|
-
return true if tags.
|
145
|
+
return true if tags.empty?
|
75
146
|
tags.all? do | tag |
|
76
147
|
tag_consumer_version tag
|
77
148
|
end
|
@@ -81,8 +152,8 @@ module PactBroker
|
|
81
152
|
versions = pact_broker_client.pacticipants.versions
|
82
153
|
Retry.while_error do
|
83
154
|
consumer_names.collect do | consumer_name |
|
84
|
-
versions.tag(pacticipant: consumer_name, version:
|
85
|
-
$stdout.puts "Tagged version #{
|
155
|
+
versions.tag(pacticipant: consumer_name, version: consumer_version_number, tag: tag)
|
156
|
+
$stdout.puts "Tagged version #{consumer_version_number} of #{consumer_name} as #{tag.inspect}"
|
86
157
|
true
|
87
158
|
end
|
88
159
|
end
|
@@ -94,22 +165,22 @@ module PactBroker
|
|
94
165
|
def publish_pact_contents(pact)
|
95
166
|
Retry.while_error do
|
96
167
|
pacts = pact_broker_client.pacticipants.versions.pacts
|
97
|
-
if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version:
|
168
|
+
if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version_number)
|
98
169
|
if merge_on_server?
|
99
170
|
$stdout.puts "A pact for this consumer version is already published. Merging contents."
|
100
171
|
else
|
101
|
-
$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.)")
|
172
|
+
$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)")
|
102
173
|
end
|
103
174
|
end
|
104
175
|
|
105
|
-
latest_pact_url = pacts.publish(pact_hash: pact, consumer_version:
|
176
|
+
latest_pact_url = pacts.publish(pact_hash: pact, consumer_version: consumer_version_number)
|
106
177
|
$stdout.puts "The latest version of this pact can be accessed at the following URL:\n#{latest_pact_url}"
|
107
178
|
true
|
108
179
|
end
|
109
180
|
end
|
110
181
|
|
111
182
|
def validate
|
112
|
-
raise PactBroker::Client::Error.new("Please specify the
|
183
|
+
raise PactBroker::Client::Error.new("Please specify the consumer_version_number") unless (consumer_version_number && consumer_version_number.to_s.strip.size > 0)
|
113
184
|
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)
|
114
185
|
raise PactBroker::Client::Error.new("No pact files found") unless (pact_file_paths && pact_file_paths.any?)
|
115
186
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rake/tasklib'
|
2
2
|
require 'pact_broker/client/git'
|
3
|
+
require 'pact_broker/client/hash_refinements'
|
3
4
|
|
4
5
|
=begin
|
5
6
|
require pact_broker/client/tasks
|
@@ -17,31 +18,52 @@ end
|
|
17
18
|
module PactBroker
|
18
19
|
module Client
|
19
20
|
class PublicationTask < ::Rake::TaskLib
|
21
|
+
using PactBroker::Client::HashRefinements
|
20
22
|
|
21
23
|
attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
|
24
|
+
attr_reader :auto_detect_version_properties, :branch, :build_url
|
22
25
|
alias_method :tags=, :tag=
|
23
26
|
alias_method :tags, :tag
|
24
27
|
|
25
28
|
def initialize name = nil, &block
|
26
29
|
@name = name
|
30
|
+
@auto_detect_version_properties = nil
|
31
|
+
@version_required = false
|
27
32
|
@pattern = 'spec/pacts/*.json'
|
28
33
|
@pact_broker_base_url = 'http://pact-broker'
|
29
34
|
rake_task &block
|
30
35
|
end
|
31
36
|
|
37
|
+
def auto_detect_version_properties= auto_detect_version_properties
|
38
|
+
@version_required = version_required || auto_detect_version_properties
|
39
|
+
@auto_detect_version_properties = auto_detect_version_properties
|
40
|
+
end
|
41
|
+
|
42
|
+
def branch= branch
|
43
|
+
@version_required = version_required || !!branch
|
44
|
+
@branch = branch
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_url= build_url
|
48
|
+
@version_required = version_required || !!build_url
|
49
|
+
@build_url = build_url
|
50
|
+
end
|
51
|
+
|
32
52
|
private
|
33
53
|
|
54
|
+
attr_reader :version_required
|
55
|
+
|
34
56
|
def rake_task &block
|
35
57
|
namespace :pact do
|
36
58
|
desc "Publish pacts to pact broker"
|
37
59
|
task task_name do
|
38
60
|
block.call(self)
|
39
61
|
require 'pact_broker/client/publish_pacts'
|
40
|
-
pact_broker_client_options =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
success = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern],
|
62
|
+
pact_broker_client_options = { write: write_method, token: pact_broker_token }
|
63
|
+
pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
|
64
|
+
pact_broker_client_options.compact!
|
65
|
+
consumer_version_params = { number: consumer_version, branch: the_branch, build_url: build_url, tags: all_tags, version_required: version_required }.compact
|
66
|
+
success = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, pact_broker_client_options).call
|
45
67
|
raise "One or more pacts failed to be published" unless success
|
46
68
|
end
|
47
69
|
end
|
@@ -53,9 +75,18 @@ module PactBroker
|
|
53
75
|
|
54
76
|
def all_tags
|
55
77
|
t = [*tags]
|
56
|
-
t << PactBroker::Client::Git.branch if tag_with_git_branch
|
78
|
+
t << PactBroker::Client::Git.branch(raise_error: true) if tag_with_git_branch
|
57
79
|
t.compact.uniq
|
58
80
|
end
|
81
|
+
|
82
|
+
def the_branch
|
83
|
+
if branch.nil? && auto_detect_version_properties != false
|
84
|
+
PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true)
|
85
|
+
else
|
86
|
+
branch
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
59
90
|
end
|
60
91
|
end
|
61
92
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'pact_broker/client/hal_client_methods'
|
2
|
+
require 'pact_broker/client/error'
|
3
|
+
require 'pact_broker/client/command_result'
|
4
|
+
|
5
|
+
module PactBroker
|
6
|
+
module Client
|
7
|
+
class Versions
|
8
|
+
class RecordDeployment
|
9
|
+
include PactBroker::Client::HalClientMethods
|
10
|
+
|
11
|
+
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording deployments. Please upgrade to version 2.80.0 or later."
|
12
|
+
|
13
|
+
def self.call(params, pact_broker_base_url, pact_broker_client_options)
|
14
|
+
new(params, pact_broker_base_url, pact_broker_client_options).call
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
18
|
+
@pact_broker_base_url = pact_broker_base_url
|
19
|
+
@pacticipant_name = params.fetch(:pacticipant_name)
|
20
|
+
@version_number = params.fetch(:version_number)
|
21
|
+
@environment_name = params.fetch(:environment_name)
|
22
|
+
@replaced_previous_deployed_version = params.fetch(:replaced_previous_deployed_version)
|
23
|
+
@output = params.fetch(:output)
|
24
|
+
@pact_broker_client_options = pact_broker_client_options
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
check_if_command_supported
|
29
|
+
record_deployment
|
30
|
+
|
31
|
+
PactBroker::Client::CommandResult.new(true, result_message)
|
32
|
+
rescue PactBroker::Client::Error => e
|
33
|
+
PactBroker::Client::CommandResult.new(false, e.message)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
39
|
+
attr_reader :pacticipant_name, :version_number, :environment_name, :replaced_previous_deployed_version, :output
|
40
|
+
attr_reader :deployed_version_resource
|
41
|
+
|
42
|
+
def check_environment_exists
|
43
|
+
index_resource
|
44
|
+
._link!("pb:environments")
|
45
|
+
.get!
|
46
|
+
._links("pb:environments")
|
47
|
+
.find!(environment_name, "No environment found with name '#{environment_name}'")
|
48
|
+
end
|
49
|
+
|
50
|
+
def record_deployment
|
51
|
+
@deployed_version_resource =
|
52
|
+
get_record_deployment_relation
|
53
|
+
.post(record_deployment_request_body)
|
54
|
+
.assert_success!
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_record_deployment_relation
|
58
|
+
record_deployment_links = get_pacticipant_version._links!("pb:record-deployment")
|
59
|
+
link_for_environment = record_deployment_links.find(environment_name)
|
60
|
+
if link_for_environment
|
61
|
+
link_for_environment
|
62
|
+
else
|
63
|
+
check_environment_exists
|
64
|
+
# Force the exception to be raised
|
65
|
+
record_deployment_links.find!(environment_name, "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}.")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_pacticipant_version
|
70
|
+
index_resource
|
71
|
+
._link!("pb:pacticipant-version")
|
72
|
+
.expand(pacticipant: pacticipant_name, version: version_number)
|
73
|
+
.get
|
74
|
+
.assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
|
75
|
+
end
|
76
|
+
|
77
|
+
def record_deployment_request_body
|
78
|
+
{ replacedPreviousDeployedVersion: replaced_previous_deployed_version }
|
79
|
+
end
|
80
|
+
|
81
|
+
def result_message
|
82
|
+
if output == "text"
|
83
|
+
message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name} in #{pact_broker_name}."
|
84
|
+
suffix = replaced_previous_deployed_version ? " Marked previous deployed version as undeployed." : ""
|
85
|
+
message + suffix
|
86
|
+
elsif output == "json"
|
87
|
+
deployed_version_resource.response.raw_body
|
88
|
+
else
|
89
|
+
""
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def pact_broker_name
|
94
|
+
is_pactflow? ? "Pactflow" : "the Pact Broker"
|
95
|
+
end
|
96
|
+
|
97
|
+
def is_pactflow?
|
98
|
+
deployed_version_resource.response.headers.keys.any?{ | header_name | header_name.downcase.include?("pactflow") }
|
99
|
+
end
|
100
|
+
|
101
|
+
def check_if_command_supported
|
102
|
+
unless index_resource.can?("pb:environments")
|
103
|
+
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'pact_broker/client/hal_client_methods'
|
2
|
+
require 'pact_broker/client/error'
|
3
|
+
require 'pact_broker/client/command_result'
|
4
|
+
|
5
|
+
module PactBroker
|
6
|
+
module Client
|
7
|
+
class Versions
|
8
|
+
class RecordUndeployment
|
9
|
+
include PactBroker::Client::HalClientMethods
|
10
|
+
|
11
|
+
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
|
12
|
+
|
13
|
+
def self.call(params, pact_broker_base_url, pact_broker_client_options)
|
14
|
+
new(params, pact_broker_base_url, pact_broker_client_options).call
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
18
|
+
@pact_broker_base_url = pact_broker_base_url
|
19
|
+
@pacticipant_name = params.fetch(:pacticipant_name)
|
20
|
+
@version_number = params.fetch(:version_number)
|
21
|
+
@environment_name = params.fetch(:environment_name)
|
22
|
+
@output = params.fetch(:output)
|
23
|
+
@pact_broker_client_options = pact_broker_client_options
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
check_environment_exists
|
28
|
+
# record_undeployment
|
29
|
+
|
30
|
+
PactBroker::Client::CommandResult.new(true, result_message)
|
31
|
+
rescue PactBroker::Client::Error => e
|
32
|
+
PactBroker::Client::CommandResult.new(false, e.message)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
38
|
+
attr_reader :pacticipant_name, :version_number, :environment_name, :replaced_previous_deployed_version, :output
|
39
|
+
attr_reader :deployed_version_resource
|
40
|
+
|
41
|
+
def check_environment_exists
|
42
|
+
deployed_versions = currently_deployed_versions_for_pacticipant
|
43
|
+
.get(version: version_number)
|
44
|
+
.embedded_entities("deployedVersions")
|
45
|
+
deployed_versions
|
46
|
+
end
|
47
|
+
|
48
|
+
def currently_deployed_versions_for_pacticipant
|
49
|
+
@currently_deployed_versions_for_pacticipant ||= index_resource
|
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)
|
57
|
+
end
|
58
|
+
|
59
|
+
def currently_deployed_versions_for_pacticipant_version
|
60
|
+
@currently_deployed_versions ||= currently_deployed_versions_for_pacticipant
|
61
|
+
.get(version: version_number)
|
62
|
+
.embedded_entities("deployedVersions")
|
63
|
+
end
|
64
|
+
|
65
|
+
# def record_deployment
|
66
|
+
# @deployed_version_resource =
|
67
|
+
# get_record_deployment_relation
|
68
|
+
# .post(record_deployment_request_body)
|
69
|
+
# .assert_success!
|
70
|
+
# end
|
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
|
95
|
+
|
96
|
+
def result_message
|
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
|
107
|
+
end
|
108
|
+
|
109
|
+
def pact_broker_name
|
110
|
+
is_pactflow? ? "Pactflow" : "the Pact Broker"
|
111
|
+
end
|
112
|
+
|
113
|
+
def is_pactflow?
|
114
|
+
deployed_version_resource.response.headers.keys.any?{ | header_name | header_name.downcase.include?("pactflow") }
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_if_command_supported
|
118
|
+
unless index_resource.can?("pb:environments")
|
119
|
+
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|