Skip to content

Commit

Permalink
feat(publish): update output text when pact already exists and merging
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 10, 2020
1 parent 94342ef commit 9b849d3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/pact_broker/client/publish_pacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def pact_broker_client
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
end

def merge_on_server?
pact_broker_client_options[:write] == :merge
end

def publish_pacts
pact_files.group_by(&:pact_name).collect do | pact_name, pact_files |
$stdout.puts "Merging #{pact_files.collect(&:path).join(", ")}" if pact_files.size > 1
Expand Down Expand Up @@ -91,7 +95,11 @@ def publish_pact_contents(pact)
Retry.while_error do
pacts = pact_broker_client.pacticipants.versions.pacts
if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version)
$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.)")
if merge_on_server?
$stdout.puts "A pact for this consumer version is already published. Merging contents."
else
$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.)")
end
end

latest_pact_url = pacts.publish(pact_hash: pact, consumer_version: consumer_version)
Expand Down

0 comments on commit 9b849d3

Please sign in to comment.