Skip to content

Commit a1f9e4f

Browse files
committed
feat: add github commit status reporting
1 parent 2da8fb6 commit a1f9e4f

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

Makefile

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PACTICIPANT := "pactflow-example-consumer"
2+
GITHUB_WEBHOOK_UUID := "04510dc1-7f0a-4ed2-997d-114bfa86f8ad"
23

3-
all: test deploy
4+
all: create_or_update_github_webhook test deploy
45

56
test:
67
npm run test:pact
@@ -33,3 +34,36 @@ tag_as_prod:
3334
--tag prod
3435

3536
deploy: can_i_deploy deploy_app tag_as_prod
37+
38+
# This webhook will update the Github commit status for this commit
39+
# so that any PRs will get a status that shows what the status of
40+
# the pact is.
41+
create_or_update_github_webhook:
42+
docker run --rm \
43+
-e PACT_BROKER_BASE_URL \
44+
-e PACT_BROKER_USERNAME \
45+
-e PACT_BROKER_PASSWORD \
46+
-v ${PWD}:${PWD} \
47+
pactfoundation/pact-cli:latest \
48+
broker create-or-update-webhook \
49+
'https://api.github.com/repos/pactflow/example-consumer/statuses/$${pactbroker.consumerVersionNumber}' \
50+
--header 'Content-Type: application/json' 'Accept: application/vnd.github.v3+json' 'Authorization: token $${user.githubCommitStatusToken}' \
51+
--request POST \
52+
--data @${PWD}/pactflow/github-commit-status-webhook.json \
53+
--uuid ${GITHUB_WEBHOOK_UUID} \
54+
--consumer ${PACTICIPANT} \
55+
--contract-published \
56+
--provider-verification-published \
57+
--description "Github commit status webhook for ${PACTICIPANT}"
58+
59+
test_github_webhook:
60+
curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${GITHUB_WEBHOOK_UUID}/execute -u ${PACT_BROKER_USERNAME}:${PACT_BROKER_PASSWORD}
61+
62+
# This should be called once before creating the webhook
63+
# with the environment variable GITHUB_TOKEN set
64+
create_github_token_secret:
65+
curl -v -X POST ${PACT_BROKER_BASE_URL}/secrets \
66+
-u ${PACT_BROKER_USERNAME}:${PACT_BROKER_PASSWORD} \
67+
-H "Content-Type: application/json" \
68+
-H "Accept: application/hal+json" \
69+
-d "{\"name\":\"githubCommitStatusToken\",\"description\":\"Github token for updating commit statuses\",\"value\":\"${GITHUB_TOKEN}\"}"

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[![Build Status](https://travis-ci.com/pactflow/example-consumer.svg?branch=master)](https://travis-ci.com/pactflow/example-consumer)
44

5-
This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [Pactflow](https://pactflow.io). It is using a public tenant on Pactflow, which you can access [here](https://test.pact.dius.com.au) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The Example Consumer/Example Provider pact is published [here](https://test.pact.dius.com.au/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest).
5+
This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [Pactflow](https://pactflow.io).
6+
7+
It is using a public tenant on Pactflow, which you can access [here](https://test.pact.dius.com.au) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pact.dius.com.au/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest).
68

79
The build "pipeline" is simulated with a Makefile, and performs the following tasks:
810

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"state": "${pactbroker.githubVerificationStatus}",
3+
"description": "Pact Verification Tests",
4+
"context": "${pactbroker.providerName} ${pactbroker.providerVersionTags}",
5+
"target_url": "${pactbroker.verificationResultUrl}"
6+
}

0 commit comments

Comments
 (0)