pact_broker-client 1.38.1 → 1.41.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 +38 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/bin/pact-broker +6 -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/base_client.rb +1 -1
- data/lib/pact_broker/client/can_i_deploy.rb +20 -3
- data/lib/pact_broker/client/cli/broker.rb +35 -10
- 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/hal/entity.rb +16 -0
- data/lib/pact_broker/client/hal/http_client.rb +37 -1
- data/lib/pact_broker/client/hal/link.rb +12 -0
- data/lib/pact_broker/client/hal/links.rb +15 -0
- data/lib/pact_broker/client/hal_client_methods.rb +8 -0
- 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 +11 -8
- 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/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 +1 -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/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 +3 -3
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +36 -7
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +64 -7
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +3 -0
- 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/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/publish_pacts_spec.rb +116 -0
- data/spec/service_providers/record_deployment_spec.rb +6 -7
- data/spec/spec_helper.rb +2 -1
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +6 -2
- metadata +41 -5
@@ -1,11 +1,8 @@
|
|
1
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
2
|
require 'pact_broker/client/hal_client_methods'
|
8
|
-
require '
|
3
|
+
require 'base64'
|
4
|
+
require 'pact_broker/client/publish_pacts_the_old_way'
|
5
|
+
require 'pact_broker/client/colorize_notices'
|
9
6
|
|
10
7
|
module PactBroker
|
11
8
|
module Client
|
@@ -13,170 +10,135 @@ module PactBroker
|
|
13
10
|
using PactBroker::Client::HashRefinements
|
14
11
|
include HalClientMethods
|
15
12
|
|
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
|
13
|
+
def self.call(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options={})
|
14
|
+
new(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options).call
|
18
15
|
end
|
19
16
|
|
20
|
-
def initialize pact_broker_base_url, pact_file_paths, consumer_version_params, pact_broker_client_options={}
|
17
|
+
def initialize pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options={}
|
21
18
|
@pact_broker_base_url = pact_broker_base_url
|
22
19
|
@pact_file_paths = pact_file_paths
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
20
|
+
@consumer_version_params = consumer_version_params
|
21
|
+
@consumer_version_number = strip(consumer_version_params[:number])
|
22
|
+
@branch = strip(consumer_version_params[:branch])
|
23
|
+
@build_url = strip(consumer_version_params[:build_url])
|
24
|
+
@tags = consumer_version_params[:tags] ? consumer_version_params[:tags].collect{ |tag| strip(tag) } : []
|
25
|
+
@options = options
|
28
26
|
@pact_broker_client_options = pact_broker_client_options
|
29
27
|
end
|
30
28
|
|
31
29
|
def call
|
32
30
|
validate
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("publish_contracts") && index_resource.can?("pb:publish-contracts")
|
32
|
+
publish_pacts
|
33
|
+
PactBroker::Client::CommandResult.new(success?, message)
|
34
|
+
else
|
35
|
+
PublishPactsTheOldWay.call(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options)
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options, :
|
42
|
-
|
43
|
-
def pact_broker_client
|
44
|
-
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def index_entry_point
|
48
|
-
@index_entry_point ||= create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
|
49
|
-
end
|
41
|
+
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_params, :consumer_version_number, :branch, :tags, :build_url, :options, :pact_broker_client_options, :response_entities
|
50
42
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def merge_on_server?
|
62
|
-
pact_broker_client_options[:write] == :merge
|
43
|
+
def request_body_for(consumer_name)
|
44
|
+
{
|
45
|
+
pacticipantName: consumer_name,
|
46
|
+
pacticipantVersionNumber: consumer_version_number,
|
47
|
+
tags: tags,
|
48
|
+
branch: branch,
|
49
|
+
buildUrl: build_url,
|
50
|
+
contracts: contracts_for(consumer_name)
|
51
|
+
}.compact
|
63
52
|
end
|
64
53
|
|
65
54
|
def publish_pacts
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end.all?
|
70
|
-
end
|
71
|
-
|
72
|
-
def merge_contents(pact_files)
|
73
|
-
MergePacts.call(pact_files.collect(&:pact_hash))
|
74
|
-
end
|
75
|
-
|
76
|
-
def pact_files
|
77
|
-
@pact_files ||= pact_file_paths.collect{ |pact_file_path| PactFile.new(pact_file_path) }
|
78
|
-
end
|
79
|
-
|
80
|
-
def consumer_names
|
81
|
-
pact_files.collect(&:consumer_name).uniq
|
55
|
+
@response_entities = consumer_names.collect do | consumer_name |
|
56
|
+
index_resource._link("pb:publish-contracts").post(request_body_for(consumer_name))
|
57
|
+
end
|
82
58
|
end
|
83
59
|
|
84
|
-
def
|
85
|
-
|
86
|
-
$stdout.puts "Publishing #{pact.pact_name} to pact broker at #{pact_broker_base_url}"
|
87
|
-
publish_pact_contents pact
|
88
|
-
rescue => e
|
89
|
-
$stderr.puts "Failed to publish #{pact.pact_name} due to error: #{e.class} - #{e}"
|
90
|
-
false
|
91
|
-
end
|
60
|
+
def success?
|
61
|
+
response_entities.all?(&:success?)
|
92
62
|
end
|
93
63
|
|
94
|
-
def
|
95
|
-
if
|
96
|
-
|
97
|
-
create_version(index_resource, consumer_name)
|
98
|
-
end
|
99
|
-
true
|
64
|
+
def message
|
65
|
+
if options[:output] == "json"
|
66
|
+
response_entities.collect(&:response).collect(&:body).to_a.to_json
|
100
67
|
else
|
101
|
-
|
68
|
+
text_message
|
102
69
|
end
|
103
70
|
end
|
104
71
|
|
105
|
-
def
|
106
|
-
|
107
|
-
if
|
108
|
-
|
72
|
+
def text_message
|
73
|
+
response_entities.flat_map do | response_entity |
|
74
|
+
if response_entity.success?
|
75
|
+
if response_entity.notices
|
76
|
+
PactBroker::Client::ColorizeNotices.call(response_entity.notices.collect{ |n| OpenStruct.new(n) } )
|
77
|
+
elsif response_entity.logs
|
78
|
+
response_entity.logs.collect do | log |
|
79
|
+
colorized_message(log)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
"Successfully published pacts"
|
83
|
+
end
|
109
84
|
else
|
110
|
-
|
85
|
+
::Term::ANSIColor.red(response_entity.response.body.to_s)
|
111
86
|
end
|
112
|
-
|
113
|
-
|
87
|
+
end.join("\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
def colorized_message(log)
|
91
|
+
color = color_for_level(log["level"])
|
92
|
+
if color
|
93
|
+
::Term::ANSIColor.send(color, log["message"])
|
114
94
|
else
|
115
|
-
|
95
|
+
log["message"]
|
116
96
|
end
|
117
97
|
end
|
118
98
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
99
|
+
def color_for_level(level)
|
100
|
+
case level
|
101
|
+
when "warn" then :yellow
|
102
|
+
when "error" then :red
|
103
|
+
when "info" then :green
|
104
|
+
else nil
|
105
|
+
end
|
106
|
+
end
|
127
107
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
108
|
+
def contracts_for(consumer_name)
|
109
|
+
pact_files_for(consumer_name).group_by(&:pact_name).values.collect do | pact_files |
|
110
|
+
$stderr.puts "Merging #{pact_files.collect(&:path).join(", ")}" if pact_files.size > 1
|
111
|
+
pact_hash = PactHash[merge_contents(pact_files)]
|
112
|
+
{
|
113
|
+
consumerName: pact_hash.consumer_name,
|
114
|
+
providerName: pact_hash.provider_name,
|
115
|
+
specification: "pact",
|
116
|
+
contentType: "application/json",
|
117
|
+
content: Base64.strict_encode64(pact_hash.to_json),
|
118
|
+
writeMode: write_mode,
|
119
|
+
onConflict: write_mode
|
120
|
+
}
|
134
121
|
end
|
135
122
|
end
|
136
123
|
|
137
|
-
def
|
138
|
-
|
139
|
-
branch: branch,
|
140
|
-
buildUrl: build_url
|
141
|
-
}.compact
|
124
|
+
def merge_contents(pact_files)
|
125
|
+
MergePacts.call(pact_files.collect(&:pact_hash))
|
142
126
|
end
|
143
127
|
|
144
|
-
def
|
145
|
-
|
146
|
-
tags.all? do | tag |
|
147
|
-
tag_consumer_version tag
|
148
|
-
end
|
128
|
+
def pact_files
|
129
|
+
@pact_files ||= pact_file_paths.collect{ |pact_file_path| PactFile.new(pact_file_path) }
|
149
130
|
end
|
150
131
|
|
151
|
-
def
|
152
|
-
|
153
|
-
Retry.while_error do
|
154
|
-
consumer_names.collect do | consumer_name |
|
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}"
|
157
|
-
true
|
158
|
-
end
|
159
|
-
end
|
160
|
-
rescue => e
|
161
|
-
$stderr.puts "Failed to tag version due to error: #{e.class} - #{e}"
|
162
|
-
false
|
132
|
+
def pact_files_for(consumer_name)
|
133
|
+
pact_files.select{ | pact_file | pact_file.consumer_name == consumer_name }
|
163
134
|
end
|
164
135
|
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version_number)
|
169
|
-
if merge_on_server?
|
170
|
-
$stdout.puts "A pact for this consumer version is already published. Merging contents."
|
171
|
-
else
|
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)")
|
173
|
-
end
|
174
|
-
end
|
136
|
+
def consumer_names
|
137
|
+
pact_files.collect(&:consumer_name).uniq
|
138
|
+
end
|
175
139
|
|
176
|
-
|
177
|
-
|
178
|
-
true
|
179
|
-
end
|
140
|
+
def write_mode
|
141
|
+
options[:merge] ? "merge" : "overwrite"
|
180
142
|
end
|
181
143
|
|
182
144
|
def validate
|
@@ -184,6 +146,10 @@ module PactBroker
|
|
184
146
|
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)
|
185
147
|
raise PactBroker::Client::Error.new("No pact files found") unless (pact_file_paths && pact_file_paths.any?)
|
186
148
|
end
|
149
|
+
|
150
|
+
def strip(maybe_string)
|
151
|
+
maybe_string.respond_to?(:strip) ? maybe_string.strip : maybe_string
|
152
|
+
end
|
187
153
|
end
|
188
154
|
end
|
189
155
|
end
|
@@ -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
|