Skip to content

Commit

Permalink
feat: use the first tag as the branch when publishing pacts using the…
Browse files Browse the repository at this point in the history
… contracts/publish endpoint
  • Loading branch information
bethesque committed Sep 7, 2021
1 parent 70f880a commit 7b903c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/contracts/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def create_or_update_version(parsed_contracts, version_params)

def create_tags(parsed_contracts, version)
(parsed_contracts.tags || []).collect do | tag_name |
tag_repository.create(version: version, name: tag_name)
tag_service.create(pacticipant_name: version.pacticipant.name, pacticipant_version_number: version.number, tag_name: tag_name)
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/lib/pact_broker/contracts/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ module Contracts
expect(subject.notices.find{ |log| log.type == "success" && log.text.include?(" published ") }).to_not be nil
end
end

context "when no branch is specified but tags are" do
before do
allow(PactBroker.configuration).to receive(:use_first_tag_as_branch).and_return(true)
end

let(:contracts_to_publish) do
ContractsToPublish.from_hash(
pacticipant_name: "Foo",
pacticipant_version_number: "1",
tags: ["a", "b"],
branch: nil,
contracts: contracts
)
end

it "uses the first tag as the branch" do
subject
expect(PactBroker::Domain::Version.order(:id).last.branch_versions.collect(&:branch_name)).to eq ["a"]
end
end
end

context "when the pact already exists" do
Expand Down

0 comments on commit 7b903c1

Please sign in to comment.