Skip to content

Commit

Permalink
fix: add missing provider version branch parameter to webhook requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 6, 2022
1 parent b8c836f commit 262dae4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class EmbeddedVersionDecorator < BaseDecorator

property :number
if PactBroker.feature_enabled?(:branches)
property :branch
property :build_url
end

Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ def branch_names
def tag_names
tags.collect(&:name)
end

def branch
raise NotImplementedError
end

def branch= branch
raise NotImplementedError
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/pact_broker/test/http_test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def create_global_webhook_for_anything_published(uuid: nil, url: "https://postma
"githubVerificationStatus" => "${pactbroker.githubVerificationStatus}",
"providerVersionNumber" => "${pactbroker.providerVersionNumber}",
"providerVersionTags" => "${pactbroker.providerVersionTags}",
"providerVersionBranch" => "${pactbroker.providerVersionBranch}",
"canIMerge" => "${pactbroker.providerMainBranchGithubVerificationStatus}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def provider_version_branch
if webhook_context.key?(:provider_version_branch)
webhook_context[:provider_version_branch] || ""
else
verification&.provider_version&.branch || ""
verification&.provider_version&.branch_names&.last || ""
end
end

Expand Down
14 changes: 12 additions & 2 deletions script/data/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@

td = PactBroker::Test::HttpTestDataBuilder.new(base_url)
td.delete_webhook(uuid: "7a5da39c-8e50-4cc9-ae16-dfa5be043e8c")
.create_global_webhook_for_contract_changed(uuid: "7a5da39c-8e50-4cc9-ae16-dfa5be043e8c")
.create_global_webhook_for_anything_published(uuid: "7a5da39c-8e50-4cc9-ae16-dfa5be043e8c")
.delete_pacticipant("foo-consumer")
.delete_pacticipant("bar-provider")
.create_pacticipant("foo-consumer")
.create_pacticipant("bar-provider")
.publish_pact(consumer: "foo-consumer", consumer_version: "1", provider: "bar-provider", content_id: "111", tag: "main")

.get_pacts_for_verification(
provider: "bar-provider",
provider_version_branch: "main",
consumer_version_selectors: [{ mainBranch: true }]
)
.verify_pact(
index: 0,
provider_version_branch: "main",
provider_version: "1",
success: true
)

rescue StandardError => e
puts "#{e.class} #{e.message}"
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact_broker/versions/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Versions

it "does not set the branch" do
subject
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
expect(td.find_version(pacticipant_name, version_number).branch_names).to be_empty
end
end

Expand All @@ -51,7 +51,7 @@ module Versions

it "does not set the branch" do
subject
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
expect(td.find_version(pacticipant_name, version_number).branch_names).to be_empty
end
end

Expand All @@ -71,7 +71,7 @@ module Versions

it "does not set the branch" do
subject
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
expect(td.find_version(pacticipant_name, version_number).branch_names).to be_empty
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/webhooks/render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module Webhooks
end

let(:provider_version) do
double("version", tags: provider_tags, branch: "provider-branch")
double("version", tags: provider_tags, branch_names: ["foo-branch", "provider-branch"])
end

let(:consumer_version) do
Expand Down

0 comments on commit 262dae4

Please sign in to comment.