Skip to content

Commit

Permalink
feat(webhooks): provide mapping to bitbucket build status names (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-reece authored and bethesque committed Jun 14, 2019
1 parent 9439cc8 commit 7bdf0c4
Show file tree
Hide file tree
Showing 3 changed files with 15 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 @@ -95,6 +95,7 @@ The following variables may be used in the request path, parameters or body, and
* `${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 ", ".
* `${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.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.

Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/webhooks/pact_and_verification_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def to_hash
'${pactbroker.consumerName}' => pact ? pact.consumer_name : "",
'${pactbroker.providerName}' => pact ? pact.provider_name : "",
'${pactbroker.githubVerificationStatus}' => github_verification_status,
'${pactbroker.bitbucketVerificationStatus}' => bitbucket_verification_status,
'${pactbroker.consumerLabels}' => pacticipant_labels(pact && pact.consumer),
'${pactbroker.providerLabels}' => pacticipant_labels(pact && pact.provider)
}
Expand All @@ -29,6 +30,13 @@ def to_hash

attr_reader :pact, :verification, :webhook_context, :base_url

def bitbucket_verification_status
if verification
verification.success ? "SUCCESSFUL" : "FAILED"
else
"INPROGRESS"
end
end

def github_verification_status
if verification
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 @@ -112,6 +112,12 @@ module Webhooks
["${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.bitbucketVerificationStatus}", "SUCCESSFUL", :pact, :verification],
["${pactbroker.bitbucketVerificationStatus}", "FAILED", :pact, :failed_verification],
["${pactbroker.bitbucketVerificationStatus}", "INPROGRESS", :nil_pact, :nil_verification],
["${pactbroker.bitbucketVerificationStatus}", "INPROGRESS", :pact_with_no_verification, :nil_verification],
["${pactbroker.bitbucketVerificationStatus}", "SUCCESSFUL", :pact_with_successful_verification, :nil_verification],
["${pactbroker.bitbucketVerificationStatus}", "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 7bdf0c4

Please sign in to comment.