From 20fed38582c4679a7d49e65de2429aed2b5d227f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 14 Oct 2023 15:07:45 +1100 Subject: [PATCH] feat: auto detect the build URL in the CLI publish pacts command --- lib/pact_broker/client/cli/pact_commands.rb | 10 +++++++++- .../client/cli/broker_publish_spec.rb | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/client/cli/pact_commands.rb b/lib/pact_broker/client/cli/pact_commands.rb index c730a36..0e6eb7a 100644 --- a/lib/pact_broker/client/cli/pact_commands.rb +++ b/lib/pact_broker/client/cli/pact_commands.rb @@ -61,7 +61,7 @@ def publish_pacts pact_files number: consumer_app_version, branch: branch, tags: tags, - build_url: options.build_url + build_url: build_url }.compact PactBroker::Client::PublishPacts.call( @@ -126,6 +126,14 @@ def consumer_app_version end end + def build_url + if options.build_url.blank? && options.auto_detect_version_properties + PactBroker::Client::Git.build_url + else + options.build_url + end + end + def explict_auto_detect_version_properties @explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties") end diff --git a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb index c572794..00f0cc9 100644 --- a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +++ b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb @@ -9,6 +9,7 @@ module PactBroker::Client::CLI allow(PactBroker::Client::PublishPacts).to receive(:call).and_return(result) allow(PactBroker::Client::Git).to receive(:branch).and_return('bar') allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6') + allow(PactBroker::Client::Git).to receive(:build_url).and_return('build_url') subject.options = OpenStruct.new(minimum_valid_options) allow($stdout).to receive(:puts) end @@ -189,7 +190,7 @@ module PactBroker::Client::CLI invoke_broker end - it 'passes in the auto detected commit sha option with version_required: true' do + it 'passes in the auto detected commit sha option' do expect(PactBroker::Client::PublishPacts).to receive(:call).with( anything, anything, @@ -200,6 +201,22 @@ module PactBroker::Client::CLI invoke_broker end + it 'determines the build URL' do + expect(PactBroker::Client::Git).to receive(:build_url) + invoke_broker + end + + it 'passes in the auto detected build URL' do + expect(PactBroker::Client::PublishPacts).to receive(:call).with( + anything, + anything, + hash_including(build_url: 'build_url'), + anything, + anything + ) + invoke_broker + end + context "with the branch specified as well" do before do subject.options = OpenStruct.new(