From 6637644febe37216b43b122a17044521cb208309 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 25 Mar 2021 10:55:55 +1100 Subject: [PATCH] feat(webhooks): support consumerVersionBranch and providerVersionBranch in the template parameters --- lib/pact_broker/doc/views/webhooks.markdown | 8 ++++--- .../test/http_test_data_builder.rb | 3 ++- .../pact_and_verification_parameters.rb | 22 +++++++++++++++++++ spec/lib/pact_broker/webhooks/render_spec.rb | 7 ++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/pact_broker/doc/views/webhooks.markdown b/lib/pact_broker/doc/views/webhooks.markdown index d0ce56637..fc3d57413 100644 --- a/lib/pact_broker/doc/views/webhooks.markdown +++ b/lib/pact_broker/doc/views/webhooks.markdown @@ -96,11 +96,13 @@ To specify an XML body, you will need to use a correctly escaped string (or use The following variables may be used in the request path, parameters or body, and will be replaced with their appropriate values at runtime. * `${pactbroker.pactUrl}`: the "permalink" URL to the newly published pact (the URL specifying the consumer version URL, rather than the "/latest" format.) -* `${pactbroker.consumerName}`: the consumer name -* `${pactbroker.providerName}`: the provider name +* `${pactbroker.consumerName}`: the consumer name. +* `${pactbroker.providerName}`: the provider name. * `${pactbroker.consumerVersionNumber}`: the version number of the most recent consumer version associated with the pact content. -* `${pactbroker.providerVersionNumber}`: the provider version number for the verification result +* `${pactbroker.providerVersionNumber}`: the provider version number for the verification result. +* `${pactbroker.consumerVersionBranch}`: the branch of the consumer version associated with the pact publication. * `${pactbroker.consumerVersionTags}`: the list of tag names for the most recent consumer version associated with the pact content, separated by ", ". +* `${pactbroker.providerVersionBranch}`: the branch of the provider version associated with the verification result. * `${pactbroker.providerVersionTags}`: the list of tag names for the provider version associated with the verification result, separated by ", ". * `${pactbroker.consumerLabels}`: the list of labels for the consumer associated with the pact content, separated by ", ". * `${pactbroker.providerLabels}`: the list of labels for the provider associated with the pact content, separated by ", ". diff --git a/lib/pact_broker/test/http_test_data_builder.rb b/lib/pact_broker/test/http_test_data_builder.rb index 1a7d4e5f0..3387f0310 100644 --- a/lib/pact_broker/test/http_test_data_builder.rb +++ b/lib/pact_broker/test/http_test_data_builder.rb @@ -175,7 +175,8 @@ def create_global_webhook_for_contract_changed(uuid: nil, url: "https://postman- "method" => "POST", "url" => url, "body" => { - "deployedProviderVersion" => "${pactbroker.currentlyDeployedProviderVersionNumber}" + "deployedProviderVersion" => "${pactbroker.currentlyDeployedProviderVersionNumber}", + "consumerVersionBranch" => "${pactbroker.consumerVersionBranch}" } } } diff --git a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb index db1892a86..e446f9647 100644 --- a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +++ b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb @@ -6,7 +6,9 @@ class PactAndVerificationParameters CONSUMER_VERSION_NUMBER = 'pactbroker.consumerVersionNumber' PROVIDER_VERSION_NUMBER = 'pactbroker.providerVersionNumber' PROVIDER_VERSION_TAGS = 'pactbroker.providerVersionTags' + PROVIDER_VERSION_BRANCH = 'pactbroker.providerVersionBranch' CONSUMER_VERSION_TAGS = 'pactbroker.consumerVersionTags' + CONSUMER_VERSION_BRANCH = 'pactbroker.consumerVersionBranch' CONSUMER_NAME = 'pactbroker.consumerName' PROVIDER_NAME = 'pactbroker.providerName' GITHUB_VERIFICATION_STATUS = 'pactbroker.githubVerificationStatus' @@ -22,7 +24,9 @@ class PactAndVerificationParameters CONSUMER_VERSION_NUMBER, PROVIDER_VERSION_NUMBER, PROVIDER_VERSION_TAGS, + PROVIDER_VERSION_BRANCH, CONSUMER_VERSION_TAGS, + CONSUMER_VERSION_BRANCH, PACT_URL, VERIFICATION_RESULT_URL, GITHUB_VERIFICATION_STATUS, @@ -47,7 +51,9 @@ def to_hash CONSUMER_VERSION_NUMBER => consumer_version_number, PROVIDER_VERSION_NUMBER => verification ? verification.provider_version_number : "", PROVIDER_VERSION_TAGS => provider_version_tags, + PROVIDER_VERSION_BRANCH => provider_version_branch, CONSUMER_VERSION_TAGS => consumer_version_tags, + CONSUMER_VERSION_BRANCH => consumer_version_branch, CONSUMER_NAME => pact ? pact.consumer_name : "", PROVIDER_NAME => pact ? pact.provider_name : "", GITHUB_VERIFICATION_STATUS => github_verification_status, @@ -107,6 +113,14 @@ def consumer_version_tags end end + def consumer_version_branch + if webhook_context[:consumer_version_branch] + webhook_context[:consumer_version_branch] + else + pact&.consumer_version&.branch || "" + end + end + def provider_version_tags if webhook_context[:provider_version_tags] webhook_context[:provider_version_tags].join(", ") @@ -119,6 +133,14 @@ def provider_version_tags end end + def provider_version_branch + if webhook_context[:provider_version_branch] + webhook_context[:provider_version_branch] + else + verification&.provider_version&.branch || "" + end + end + def pacticipant_labels pacticipant pacticipant && pacticipant.labels ? pacticipant.labels.collect(&:name).join(", ") : "" end diff --git a/spec/lib/pact_broker/webhooks/render_spec.rb b/spec/lib/pact_broker/webhooks/render_spec.rb index 5430b6637..6dda7a1ca 100644 --- a/spec/lib/pact_broker/webhooks/render_spec.rb +++ b/spec/lib/pact_broker/webhooks/render_spec.rb @@ -71,11 +71,11 @@ module Webhooks end let(:provider_version) do - double("version", tags: provider_tags) + double("version", tags: provider_tags, branch: "provider-branch") end let(:consumer_version) do - double("version", tags: consumer_tags) + double("version", tags: consumer_tags, branch: "consumer-branch") end let(:provider_tags) do @@ -122,7 +122,10 @@ module Webhooks ["${pactbroker.verificationResultUrl}", "http://verification", :pact_with_successful_verification, :nil_verification], ["${pactbroker.verificationResultUrl}", "http://verification", :pact_with_successful_verification, :verification], ["${pactbroker.providerVersionTags}", "test, prod", :pact_with_successful_verification, :verification], + ["${pactbroker.providerVersionBranch}", "provider-branch", :pact_with_successful_verification, :verification], + ["${pactbroker.providerVersionBranch}", "", :pact_with_no_verification, :nil_verification], ["${pactbroker.consumerVersionTags}", "test", :pact_with_successful_verification, :verification], + ["${pactbroker.consumerVersionBranch}", "consumer-branch", :pact_with_successful_verification, :verification], ["${pactbroker.consumerLabels}", "foo, bar", :pact_with_successful_verification, :verification], ["${pactbroker.providerLabels}", "finance, IT", :pact, :nil_verification], ]