Skip to main content

One post tagged with "verification"

View All Tags

ยท 2 min read

If you're using Travis CI, Code Climate, or one of many other CI tools with Github, you've probably noticed the little checklist of items that shows just above the "merge" button when you open a pull request.

commit-statuses

These are called commit "statuses", and there is a Github API for reporting these (Gitlab also has a similar API). If you are using a git sha for the consumer version number when you publish your pacts, you can now use Pact Broker webhooks to report the verification statuses of your pacts back to Github.

To do this, open up your Pact Broker API Browser, and click on the NON-GET button next to the pb:webhooks relation. Modify the JSON below to match your consumer, repository and Github auth details (we recommend you make a separate token for this purpose with the repo:status grant), and click Make Request.

{
"consumer": {
"name": "<consumer name>"
},
"events": [
{
"name": "contract_published"
},
{
"name": "provider_verification_published"
}
],
"request": {
"method": "POST",
"url": "https://api.github.com/repos/<organization>/<project>/statuses/${pactbroker.consumerVersionNumber}",
"headers": {
"Content-Type": "application/json"
},
"body": {
"state": "${pactbroker.githubVerificationStatus}",
"description": "Pact Verification Tests ${pactbroker.providerVersionTags}",
"context": "${pactbroker.providerName}",
"target_url": "${pactbroker.verificationResultUrl}"
},
"username": "USERNAME",
"password": "PASSWORD"
}
}

If all your consumer names match their repository names in Github, you can make this a global webhook by removing the consumer node, and replacing the hardcoded <project> name in the URL with the parameter ${pactbroker.consumerName}.

Want to use this cool feature? You'll need version 2.47.1 or later of the Pact Broker.

Check out the webhook template library for more handy webhooks.