How to deal with late required status checks? #24695
-
I maintain a bot which manages merges on the behalf of developers. The bot will attempt to merge the PR once all checks and statuses are passing. The problem is that sometimes their conclusions might arrive late, therefore relying on the current statuses available through the “List commit statuses for a reference” or “List check runs for a check suite” APIs, although correct, might fail because some required status has not yet been delivered. My first thought was to fetch all required checks’ names from the Github API and verify that they’ve all concluded before attempting the merge, although to my knowledge no such endpoint exists, which is why I’ve opted for the following “trial-and-error” approach: ignore the merge failure “Merge cannot be performed” (status code 405) if it fails because some required status is missing. So far I have found two of such cases:
For detecting those scenarios, it doesn’t feel good to rely on string matching on the error message e.g.
or It’s also possible that I’m misusing those APIs, in which case I welcome suggestions for how to better work around those scenarios. I don’t know, maybe there’s an event which tells when a merge request is mergeable? That would be handy. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found out the required status checks can be queried ahead-of-time: https://docs.github.com/en/rest/reference/repos#get-status-checks-protection |
Beta Was this translation helpful? Give feedback.
I found out the required status checks can be queried ahead-of-time: https://docs.github.com/en/rest/reference/repos#get-status-checks-protection