I am creating a Github app that listens for deployment_status.created
webhook events. The webhook is triggered when a PR is automatically deployed (using a 3rd party Github app).
When the deployment has a certain state, e.g. success, I want to add a comment to the corresponding PR.
My example code:
app.on('deployment_status.created', async (context) => {
const deployment_status = context.payload.deployment_status
if (deployment_status.state === 'success') {
// TODO: comment on the corresponding PR
}
})
How do I get the corresponding PR?
NB. There seems to be nothing in the payload for it (https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#deployment_status)
As you pointed, seems like deployment_status
payload is not offering the pull request URL or id
so you can directly post a comment.
What I think it's available is the ref
or sha
in the payload: https://github.com/octokit/webhooks/blob/6a8fec1a9e76780bba12b75291be104a1697d300/schema.d.ts#L1774-L1775
With those you can list the PR's associated I think: https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit
Still I don't know if it would be the best solution.
I invite you to post this issue (and look for potential existing ones) in https://github.com/octokit/rest.js/discussions/categories/q-a I think you will get faster feedback there.