Reading:
Publishing Pact verification statuses to Github

Publishing Pact verification statuses to Github

Matt Fellows
Updated

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 (it is already available on Pactflow).

Check out the webhook template library for more handy webhooks.

We ❤️ OSS (or why build an open source company?)
15 April 2021

We ❤️ OSS (or why build an open source company?)

We ❤️ open source. Pactflow was created to enable sustainable development of Pact and its ecosystem. Learn more about how we think about and balance our open source and commercial tensions.

6 min read

Image
By Matt Fellows
Proving E2E tests are a Scam

Proving E2E tests are a Scam

"We can see that in this example Contract Testing requires approximately a tenth of the compute resources yet provides twice the number of test fixtures. An important takeaway for me was that the cost of testing your contracts doesn’t depend on the size of your system."

14 min read

By Administrator
arrow-up icon