Skip to content

Commit

Permalink
feat: add webhook template parameter for GItlab verification statuses (
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelAlejandro authored Aug 31, 2021
1 parent d3c615c commit 390ae0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact_broker/doc/views/webhooks.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/pact_broker/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/pact_broker/webhooks/pact_and_verification_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/pact_broker/webhooks/render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 390ae0d

Please sign in to comment.