diff --git a/lib/pact_broker/client/cli/pact_commands.rb b/lib/pact_broker/client/cli/pact_commands.rb index e41f3b4f..b89d22f3 100644 --- a/lib/pact_broker/client/cli/pact_commands.rb +++ b/lib/pact_broker/client/cli/pact_commands.rb @@ -59,8 +59,7 @@ def publish_pacts pact_files number: options.consumer_app_version, branch: branch, tags: tags, - build_url: options.build_url, - version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties) + build_url: options.build_url }.compact PactBroker::Client::PublishPacts.call( diff --git a/lib/pact_broker/client/publish_pacts_the_old_way.rb b/lib/pact_broker/client/publish_pacts_the_old_way.rb index 07ef9ec8..019e111f 100644 --- a/lib/pact_broker/client/publish_pacts_the_old_way.rb +++ b/lib/pact_broker/client/publish_pacts_the_old_way.rb @@ -42,7 +42,7 @@ def call private - attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options, :version_required + attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options def pact_broker_client @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options) diff --git a/lib/pact_broker/client/tasks/publication_task.rb b/lib/pact_broker/client/tasks/publication_task.rb index 84f36554..08af69a3 100644 --- a/lib/pact_broker/client/tasks/publication_task.rb +++ b/lib/pact_broker/client/tasks/publication_task.rb @@ -28,31 +28,25 @@ class PublicationTask < ::Rake::TaskLib def initialize name = nil, &block @name = name @auto_detect_version_properties = nil - @version_required = false @pattern = 'spec/pacts/*.json' @pact_broker_base_url = 'http://pact-broker' rake_task &block end def auto_detect_version_properties= auto_detect_version_properties - @version_required = version_required || auto_detect_version_properties @auto_detect_version_properties = auto_detect_version_properties end def branch= branch - @version_required = version_required || !!branch @branch = branch end def build_url= build_url - @version_required = version_required || !!build_url @build_url = build_url end private - attr_reader :version_required - def rake_task &block namespace :pact do desc "Publish pacts to pact broker" @@ -62,7 +56,7 @@ def rake_task &block pact_broker_client_options = { write: write_method, token: pact_broker_token } pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any? pact_broker_client_options.compact! - consumer_version_params = { number: consumer_version, branch: the_branch, build_url: build_url, tags: all_tags, version_required: version_required }.compact + consumer_version_params = { number: consumer_version, branch: the_branch, build_url: build_url, tags: all_tags }.compact result = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, {}, pact_broker_client_options).call $stdout.puts result.message raise "One or more pacts failed to be published" unless result.success 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 52a28a4c..19e44a4a 100644 --- a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +++ b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb @@ -30,7 +30,7 @@ module PactBroker::Client::CLI expect(PactBroker::Client::PublishPacts).to receive(:call).with( "http://pact-broker", ["spec/support/cli_test_pacts/foo.json"], - { number: "1.2.3", tags: [], version_required: false }, + { number: "1.2.3", tags: [] }, {}, { pact_broker_base_url: 'http://pact-broker' } ) @@ -151,7 +151,7 @@ module PactBroker::Client::CLI expect(PactBroker::Client::PublishPacts).to receive(:call).with( anything, anything, - hash_including(branch: "main", version_required: true), + hash_including(branch: "main"), anything, anything ) @@ -159,32 +159,6 @@ module PactBroker::Client::CLI end end - context "with --auto-detect-version-properties on by default" do - before do - subject.options = OpenStruct.new( - minimum_valid_options.merge(auto_detect_version_properties: true) - ) - allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false) - end - - it "determines the git branch name" do - expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false) - invoke_broker - end - - it "passes in the auto detected branch option with version_required: false" do - expect(PactBroker::Client::PublishPacts).to receive(:call).with( - anything, - anything, - hash_including(branch: "bar", version_required: false), - anything, - anything - ) - invoke_broker - end - end - - context "with --auto-detect-version-properties specified explicitly" do before do subject.options = OpenStruct.new( @@ -198,11 +172,11 @@ module PactBroker::Client::CLI invoke_broker end - it "passes in the auto detected branch option with version_required: true" do + it "passes in the auto detected branch option" do expect(PactBroker::Client::PublishPacts).to receive(:call).with( anything, anything, - hash_including(branch: "bar", version_required: true), + hash_including(branch: "bar"), anything, anything ) @@ -220,7 +194,7 @@ module PactBroker::Client::CLI expect(PactBroker::Client::PublishPacts).to receive(:call).with( anything, anything, - hash_including(branch: "specified-branch", version_required: true), + hash_including(branch: "specified-branch"), anything, anything ) diff --git a/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb b/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb index a997b269..5ff881cd 100644 --- a/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +++ b/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb @@ -37,7 +37,6 @@ module Client let(:tags) { nil } let(:branch) { nil } let(:build_url) { nil } - let(:version_required) { false } let(:pact_hash) { { consumer: { name: 'Consumer'}, provider: { name: 'Provider' }, interactions: [] } } let(:pact_hash_2) { {consumer: { name: 'Foo' }, provider: { name: 'Bar' }, interactions: [] } } let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")} @@ -48,8 +47,7 @@ module Client number: consumer_version, branch: branch, tags: tags, - build_url: build_url, - version_required: version_required + build_url: build_url } end let(:pact_broker_client_options) do diff --git a/spec/lib/pact_broker/client/tasks/publication_task_spec.rb b/spec/lib/pact_broker/client/tasks/publication_task_spec.rb index 6908be3f..1e947de1 100644 --- a/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +++ b/spec/lib/pact_broker/client/tasks/publication_task_spec.rb @@ -33,7 +33,7 @@ module PactBroker::Client context "when pacts are succesfully published" do it "invokes PublishPacts with the default values" do - expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [], version_required: false}, {}, {}).and_return(publish_pacts) + expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [] }, {}, {}).and_return(publish_pacts) expect(publish_pacts).to receive(:call).and_return(result) Rake::Task['pact:publish'].execute end @@ -57,7 +57,7 @@ module PactBroker::Client end it "invokes PublishPacts with the write method set" do - expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [], version_required: false }, {}, {write: :merge}).and_return(publish_pacts) + expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [] }, {}, {write: :merge}).and_return(publish_pacts) expect(publish_pacts).to receive(:call).and_return(result) Rake::Task['pact:publish:merge'].execute end @@ -184,7 +184,7 @@ module PactBroker::Client expect(PactBroker::Client::PublishPacts).to receive(:new).with( @pact_broker_base_url, pact_file_list, - { number: "1.2.3", tags: [@tag], branch: "foo", version_required: false}, + { number: "1.2.3", tags: [@tag], branch: "foo" }, {}, { basic_auth: @pact_broker_basic_auth, token: @pact_broker_token } )