Get PR associated with status event

I have a webhook setup to receive status events.  The status event doesn’t contain any information about the pull request that created the status.  It has a commit hash, but a commit can be associated with multiple pull requests so I can’t rely on that.  In my case, I’m interested in status events for CI so there is a target_url property I could use, but I would have to enumerate all open PRs, enumerate all statuses for each PR and match it to the target_url which seems very expensive.  Ideally, the status event should include the url to the PR.  Is there another way to get the PR?  Thanks.

Hey @stevel-msft,

Thanks for being here! Statuses do not link directly to Pull requests, they are instead associated with specific commits. When the state of status changes it can affect multiple pull requests.  I’ve taken your suggestion to include the url and passed it along to the appropriate teams. 

I see.  Ultimately what I’m doing is after the status is complete, I call into the CI system (AzDevOps in this case) to get the test failures and post that back to the pull request.  I was able to work around this as the AzDevOps side has the PR number so I can find my way back to the PR and post the comment.  However, I wasn’t sure if this would be available in other CI systems so wanted to rely on metadata from the GitHub side.  In anycase, thanks for following up on this!

1 Like