Skip to content

Commit

Permalink
refactor: remove unused version_required flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 14, 2023
1 parent a29d1de commit 4cb5c04
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 47 deletions.
3 changes: 1 addition & 2 deletions lib/pact_broker/client/cli/pact_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/publish_pacts_the_old_way.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions lib/pact_broker/client/tasks/publication_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
36 changes: 5 additions & 31 deletions spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
)
Expand Down Expand Up @@ -151,40 +151,14 @@ 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
)
invoke_broker
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(
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact_broker/client/tasks/publication_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }
)
Expand Down

0 comments on commit 4cb5c04

Please sign in to comment.