Skip to content

Commit

Permalink
feat(webhooks): support consumerVersionBranch and providerVersionBran…
Browse files Browse the repository at this point in the history
…ch in the template parameters
  • Loading branch information
bethesque committed Mar 24, 2021
1 parent 110578d commit 6637644
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/pact_broker/doc/views/webhooks.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 ", ".
Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/test/http_test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions lib/pact_broker/webhooks/pact_and_verification_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(", ")
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/pact_broker/webhooks/render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
]
Expand Down

0 comments on commit 6637644

Please sign in to comment.