From 390ae0d8aa52e696affefc70b310a6af4f97cd1a Mon Sep 17 00:00:00 2001 From: AbelAlejandro Date: Tue, 31 Aug 2021 03:36:12 +0200 Subject: [PATCH] feat: add webhook template parameter for GItlab verification statuses (#493) --- lib/pact_broker/doc/views/webhooks.markdown | 1 + lib/pact_broker/locale/en.yml | 1 + .../webhooks/pact_and_verification_parameters.rb | 11 +++++++++++ spec/lib/pact_broker/webhooks/render_spec.rb | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/lib/pact_broker/doc/views/webhooks.markdown b/lib/pact_broker/doc/views/webhooks.markdown index fc3d57413..6f8c83b13 100644 --- a/lib/pact_broker/doc/views/webhooks.markdown +++ b/lib/pact_broker/doc/views/webhooks.markdown @@ -108,6 +108,7 @@ The following variables may be used in the request path, parameters or body, and * `${pactbroker.providerLabels}`: the list of labels for the provider associated with the pact content, 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.bitbucketVerificationStatus}`: the verification status using the correct keywords for posting to the the [Bitbucket commit status API](https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/). +* `${pactbroker.gitlabVerificationStatus}`: the verification status using the correct keywords for posting to the the [Gitlab Commits API](https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit). * `${pactbroker.verificationResultUrl}`: the URL to the relevant verification result. Example usage: diff --git a/lib/pact_broker/locale/en.yml b/lib/pact_broker/locale/en.yml index 468cca69a..e64e66d1a 100644 --- a/lib/pact_broker/locale/en.yml +++ b/lib/pact_broker/locale/en.yml @@ -39,6 +39,7 @@ en: githubVerificationStatus: The verification status using the correct keywords for posting to the Github commit status API. See https://developer.github.com/v3/repos/statuses bitbucketVerificationStatus: The verification status using the correct keywords for posting to the Bitbucket commit status API. See https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/ azureDevOpsVerificationStatus: The verification status using the correct keywords for posting to the Azure DevOps GitStatusState API. See https://docs.microsoft.com/en-us/rest/api/azure/devops/git/statuses/create?view=azure-devops-rest-6.0 + gitlabVerificationStatus: The verification status using the correct keywords for posting to the Gitlab Commits API. See https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit eventName: The name of the event that triggered the webhook currentlyDeployedProviderVersionNumber: The version number of the currently deployed provider version (when used in a template, the webhook will be triggered once for each currently deployed provider version) no_webhooks_enabled_for_event: No enabled webhooks found for the detected events diff --git a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb index d96d021ad..d6f6e4a23 100644 --- a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +++ b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb @@ -14,6 +14,7 @@ class PactAndVerificationParameters GITHUB_VERIFICATION_STATUS = "pactbroker.githubVerificationStatus" BITBUCKET_VERIFICATION_STATUS = "pactbroker.bitbucketVerificationStatus" AZURE_DEV_OPS_VERIFICATION_STATUS = "pactbroker.azureDevOpsVerificationStatus" + GITLAB_VERIFICATION_STATUS = "pactbroker.gitlabVerificationStatus" CONSUMER_LABELS = "pactbroker.consumerLabels" PROVIDER_LABELS = "pactbroker.providerLabels" EVENT_NAME = "pactbroker.eventName" @@ -33,6 +34,7 @@ class PactAndVerificationParameters GITHUB_VERIFICATION_STATUS, BITBUCKET_VERIFICATION_STATUS, AZURE_DEV_OPS_VERIFICATION_STATUS, + GITLAB_VERIFICATION_STATUS, CONSUMER_LABELS, PROVIDER_LABELS, EVENT_NAME, @@ -61,6 +63,7 @@ def to_hash GITHUB_VERIFICATION_STATUS => github_verification_status, BITBUCKET_VERIFICATION_STATUS => bitbucket_verification_status, AZURE_DEV_OPS_VERIFICATION_STATUS => azure_dev_ops_verification_status, + GITLAB_VERIFICATION_STATUS => gitlab_verification_status, CONSUMER_LABELS => pacticipant_labels(pact && pact.consumer), PROVIDER_LABELS => pacticipant_labels(pact && pact.provider), EVENT_NAME => event_name, @@ -96,6 +99,14 @@ def azure_dev_ops_verification_status end end + def gitlab_verification_status + if verification + verification.success ? "success" : "failed" + else + "pending" + end + end + def verification_url if verification PactBroker::Api::PactBrokerUrls.verification_url(verification, base_url) diff --git a/spec/lib/pact_broker/webhooks/render_spec.rb b/spec/lib/pact_broker/webhooks/render_spec.rb index 0e9197d4c..9039a6f4f 100644 --- a/spec/lib/pact_broker/webhooks/render_spec.rb +++ b/spec/lib/pact_broker/webhooks/render_spec.rb @@ -124,6 +124,12 @@ module Webhooks ["${pactbroker.azureDevOpsVerificationStatus}", "pending", :pact_with_no_verification, :nil_verification], ["${pactbroker.azureDevOpsVerificationStatus}", "succeeded", :pact_with_successful_verification, :nil_verification], ["${pactbroker.azureDevOpsVerificationStatus}", "failed", :pact_with_failed_verification, :nil_verification], + ["${pactbroker.gitlabVerificationStatus}", "success", :pact, :verification], + ["${pactbroker.gitlabVerificationStatus}", "failed", :pact, :failed_verification], + ["${pactbroker.gitlabVerificationStatus}", "pending", :nil_pact, :nil_verification], + ["${pactbroker.gitlabVerificationStatus}", "pending", :pact_with_no_verification, :nil_verification], + ["${pactbroker.gitlabVerificationStatus}", "success", :pact_with_successful_verification, :nil_verification], + ["${pactbroker.gitlabVerificationStatus}", "failed", :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],