Skip to content

Commit

Permalink
feat: auto detect the build URL in the CLI publish pacts command
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 14, 2023
1 parent 1131958 commit 20fed38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/pact_broker/client/cli/pact_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 20fed38

Please sign in to comment.