Get corresponding PR from Github deployment status webhook

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 (Webhook events and payloads - GitHub Docs)

1 Like