diff --git a/lib/pact_broker/doc/views/webhooks.markdown b/lib/pact_broker/doc/views/webhooks.markdown index c67405b03..718deeab0 100644 --- a/lib/pact_broker/doc/views/webhooks.markdown +++ b/lib/pact_broker/doc/views/webhooks.markdown @@ -90,6 +90,8 @@ The following variables may be used in the request parameters or body, and will `${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.consumerVersionTags}`: the list of tag names for the most recent consumer version associated with the pact content, separated by ", ". +`${pactbroker.providerVersionTags}`: the list of tag names for the provider version associated with the verification result, separated by ", ". `${pactbroker.githubVerificationStatus}`: the verification status using the correct keywords for posting to the the [Github commit status API](https://developer.github.com/v3/repos/statuses). `${pactbroker.pactUrl}`: the "permalink" URL to the newly published pact (the URL specifying the consumer version URL, rather than the "/latest" format.) `${pactbroker.verificationResultUrl}`: the URL to the relevant verification result. diff --git a/lib/pact_broker/domain/version.rb b/lib/pact_broker/domain/version.rb index 73701b6ab..de528c8d8 100644 --- a/lib/pact_broker/domain/version.rb +++ b/lib/pact_broker/domain/version.rb @@ -11,7 +11,7 @@ class Version < Sequel::Model set_primary_key :id one_to_many :pact_publications, order: :revision_number, class: "PactBroker::Pacts::PactPublication", key: :consumer_version_id associate(:many_to_one, :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id) - one_to_many :tags, :reciprocal => :version + one_to_many :tags, :reciprocal => :version, order: :created_at dataset_module do include PactBroker::Repositories::Helpers diff --git a/lib/pact_broker/webhooks/render.rb b/lib/pact_broker/webhooks/render.rb index 715cb6f55..d64d60df5 100644 --- a/lib/pact_broker/webhooks/render.rb +++ b/lib/pact_broker/webhooks/render.rb @@ -4,16 +4,19 @@ class Render TEMPLATE_PARAMETER_REGEXP = /\$\{pactbroker\.[^\}]+\}/ - def self.call(template, pact, verification = nil, &escaper) + def self.call(template, pact, trigger_verification = nil, &escaper) base_url = PactBroker.configuration.base_url + verification = trigger_verification || (pact && pact.latest_verification) params = { '${pactbroker.pactUrl}' => pact ? PactBroker::Api::PactBrokerUrls.pact_url(base_url, pact) : "", - '${pactbroker.verificationResultUrl}' => verification_url(pact, verification), + '${pactbroker.verificationResultUrl}' => verification_url(verification), '${pactbroker.consumerVersionNumber}' => pact ? pact.consumer_version_number : "", '${pactbroker.providerVersionNumber}' => verification ? verification.provider_version_number : "", + '${pactbroker.providerVersionTags}' => provider_version_tags(verification), + '${pactbroker.consumerVersionTags}' => consumer_version_tags(pact), '${pactbroker.consumerName}' => pact ? pact.consumer_name : "", '${pactbroker.providerName}' => pact ? pact.provider_name : "", - '${pactbroker.githubVerificationStatus}' => github_verification_status(pact, verification) + '${pactbroker.githubVerificationStatus}' => github_verification_status(verification) } if escaper @@ -27,21 +30,33 @@ def self.call(template, pact, verification = nil, &escaper) end end - def self.github_verification_status pact, verification + def self.github_verification_status verification if verification verification.success ? "success" : "failure" - elsif pact && pact.latest_verification - pact.latest_verification.success ? "success" : "failure" - elsif pact + else "pending" + end + end + + def self.verification_url verification + if verification + PactBroker::Api::PactBrokerUrls.verification_url(verification, PactBroker.configuration.base_url) else "" end end - def self.verification_url pact, verification - if verification || (pact && pact.latest_verification) - PactBroker::Api::PactBrokerUrls.verification_url(verification || pact.latest_verification, PactBroker.configuration.base_url) + def self.consumer_version_tags pact + if pact + pact.consumer_version.tags.collect(&:name).join(", ") + else + "" + end + end + + def self.provider_version_tags verification + if verification + verification.provider_version.tags.collect(&:name).join(", ") else "" end diff --git a/spec/lib/pact_broker/webhooks/render_spec.rb b/spec/lib/pact_broker/webhooks/render_spec.rb index 1e1a38885..15ca02992 100644 --- a/spec/lib/pact_broker/webhooks/render_spec.rb +++ b/spec/lib/pact_broker/webhooks/render_spec.rb @@ -14,13 +14,19 @@ module Webhooks end let(:pact) do - instance_double("pact", consumer_version_number: "1.2.3+foo", consumer_name: "Foo", provider_name: "Bar", latest_verification: nil) + double("pact", + consumer_version: consumer_version, + consumer_version_number: "1.2.3+foo", + consumer_name: "Foo", + provider_name: "Bar", + latest_verification: nil) end let(:pact_with_no_verification) { pact } let(:pact_with_successful_verification) do - instance_double("pact", + double("pact", + consumer_version: consumer_version, consumer_version_number: "1.2.3+foo", consumer_name: "Foo", provider_name: "Bar", @@ -28,7 +34,8 @@ module Webhooks end let(:pact_with_failed_verification) do - instance_double("pact", + double("pact", + consumer_version: consumer_version, consumer_version_number: "1.2.3+foo", consumer_name: "Foo", provider_name: "Bar", @@ -36,11 +43,27 @@ module Webhooks end let(:verification) do - instance_double("verification", provider_version_number: "3", success: true) + double("verification", provider_version_number: "3", success: true, provider_version: provider_version) end let(:failed_verification) do - instance_double("verification", provider_version_number: "3", success: false) + double("verification", provider_version_number: "3", success: false, provider_version: provider_version) + end + + let(:provider_version) do + double("version", tags: provider_tags) + end + + let(:consumer_version) do + double("version", tags: consumer_tags) + end + + let(:provider_tags) do + [ double("tag", name: "test"), double("tag", name: "prod") ] + end + + let(:consumer_tags) do + [ double("tag", name: "test") ] end let(:nil_pact) { nil } @@ -57,13 +80,15 @@ module Webhooks ["${pactbroker.providerName}", "Bar", :pact, :verification], ["${pactbroker.githubVerificationStatus}", "success", :pact, :verification], ["${pactbroker.githubVerificationStatus}", "failure", :pact, :failed_verification], - ["${pactbroker.githubVerificationStatus}", "", :nil_pact, :nil_verification], + ["${pactbroker.githubVerificationStatus}", "pending", :nil_pact, :nil_verification], ["${pactbroker.githubVerificationStatus}", "pending", :pact_with_no_verification, :nil_verification], ["${pactbroker.githubVerificationStatus}", "success", :pact_with_successful_verification, :nil_verification], ["${pactbroker.githubVerificationStatus}", "failure", :pact_with_failed_verification, :nil_verification], ["${pactbroker.verificationResultUrl}", "", :pact_with_no_verification, :nil_verification], ["${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.consumerVersionTags}", "test", :pact_with_successful_verification, :verification], ] TEST_CASES.each do | (template, expected_output, pact_var_name, verification_var_name) |