You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh pr checks <pr> --required should not fail when there are no required checks #9682
Describe the feature or problem you’d like to solve
I have a script that wants to wait for required checks. If there are no required checks at all, that should count as an instant success and not a failure. AFAICT, it's a bit of a pain if I want to actually tell between "checks failed" or "no checks".
Proposed solution
Option 1: return a 0 exit code if there are no required checks.
Option 2: return a distinct (& documented!) exit code for the "no required checks" scenario so it can be specifically handled.
Option 1: return a 0 exit code if there are no required checks.
This makes sense, and I think this might be a bug. I've done a bit of digging, and it seems like there is a design intention to exit 0 when there are no results:
Digging further, it looks like we currently return an error (which I understand exits as 1) when no checks are found, and this applies to gh pr checks with the --required flag and without:
@BagToad Thanks for looking into this. I'm not sure this approach is going to work though, sorry.
There are more details in this comment by Mislav. There seems to be an underlying issue that:
The branch for the PR might not report any checks if the branch was just created, so before any Checks nor Statuses got registered by external services yet. Re-running the command a few seconds later could show that there are now checks registered as “pending”.
If this is true, this is not a safe change to make with the consequences being that PRs that may have failing checks could be considered passing.
We could adjust the exit code in this case to a distinct one as originally proposed. It could be argued that it's breaking but I'm content to say that the extent of the stability of our exit codes is zero/non-zero if not specified (e.g. 8 is for pending).
In the meantime, @clarityflowers, just curious what you prefer about scripting against a distinct exit code vs checking the stderr for "no checks reported"? Cheers.
In the meantime, @clarityflowers, just curious what you prefer about scripting against a distinct exit code vs checking the stderr for "no checks reported"? Cheers.
@williammartin redirecting stderr and then comparing against it while also still having to check the exit code for an actual error is much more of a pain then just checking $? and moving on. It's also more robust, since you demonstrated in that PR that you're perfectly happy to update the wording of an error message! The crucial word here is "documented" – I'd like a way to check for this scenario that's guaranteed to stable against minor updates.
Thanks, that's what I imagined, and makes sense. I have an issue open somewhere to write a document about what the version stability guarantees of the CLI actually are because it doesn't seem to have ever been strictly semver and right now it's all a bit wibbly wobbly and likely to cause frustration in the future.
Do you have any concerns about the API returning inconsistent view of checks under some circumstances (seems to be when the branch is newly created)? Is that something you are content to handle on your end?
It'd definitely be nice if it could tell the difference between "no checks" and "checks haven't started yet" but that feels like a separate issue from this one! My current scripts just throw a sleep in to make sure checks have the chance to load right now.
As I think about this more, I get more and more concerned about the existing UX when it comes to checks that are not yet registered. We have special cased 0 checks as an error because there is a delay between the PR being created and first party or third party checks being registered against the PR. However, this delay is equally true for n checks. There's no way that I know of to guarantee that a slow third party hasn't yet registered a check. For example, we may have 4 checks that have all passed, but a slow third party has not registered the 5th. This is indistinguishable from it not existing.
I think that instead of a separate status code, I would like this discrepancy to be called out and explicitly opted into via a flag. That way users can clearly understand that relying on this behaviour comes with risks. @clarityflowers do you think a flag like --succeed-on-no-checks would work for your case, with the behaviour being that we would exit 0 if this flag were provided and the API returned no checks.
Activity
BagToad commentedon Oct 1, 2024
👋 Hey @clarityflowers. Thank you for opening this ✨
This makes sense, and I think this might be a bug. I've done a bit of digging, and it seems like there is a design intention to exit
0when there are no results:cli/cmd/gh/main.go
Lines 140 to 144 in 3f3acde
Digging further, it looks like we currently return an error (which I understand exits as
1) when no checks are found, and this applies togh pr checkswith the--requiredflag and without:cli/pkg/cmd/pr/checks/checks.go
Lines 298 to 306 in 3f3acde
I suspect this is a bug for both cases.
Acceptance Criteriagh pr checks <pr> --requiredreturns a0exit code when no checks are foundgh pr checks <pr>returns a0exit code when no checks are foundI have opened a PR for the above: #9691New AC is here: #9682 (comment)
williammartin commentedon Oct 2, 2024
@BagToad Thanks for looking into this. I'm not sure this approach is going to work though, sorry.
There are more details in this comment by Mislav. There seems to be an underlying issue that:
If this is true, this is not a safe change to make with the consequences being that PRs that may have failing checks could be considered passing.
We could adjust the exit code in this case to a distinct one as originally proposed. It could be argued that it's breaking but I'm content to say that the extent of the stability of our exit codes is zero/non-zero if not specified (e.g.
8is for pending).In the meantime, @clarityflowers, just curious what you prefer about scripting against a distinct exit code vs checking the
stderrfor "no checks reported"? Cheers.clarityflowers commentedon Oct 2, 2024
@williammartin redirecting stderr and then comparing against it while also still having to check the exit code for an actual error is much more of a pain then just checking
$?and moving on. It's also more robust, since you demonstrated in that PR that you're perfectly happy to update the wording of an error message! The crucial word here is "documented" – I'd like a way to check for this scenario that's guaranteed to stable against minor updates.williammartin commentedon Oct 2, 2024
Thanks, that's what I imagined, and makes sense. I have an issue open somewhere to write a document about what the version stability guarantees of the CLI actually are because it doesn't seem to have ever been strictly semver and right now it's all a bit wibbly wobbly and likely to cause frustration in the future.
Do you have any concerns about the API returning inconsistent view of checks under some circumstances (seems to be when the branch is newly created)? Is that something you are content to handle on your end?
clarityflowers commentedon Oct 2, 2024
It'd definitely be nice if it could tell the difference between "no checks" and "checks haven't started yet" but that feels like a separate issue from this one! My current scripts just throw a
sleepin to make sure checks have the chance to load right now.BagToad commentedon Oct 4, 2024
Acceptance Criteria
gh pr checks <pr> --requiredreturns a unique non-zero exit code when no checks are foundgh pr checks <pr>returns a unique non-zero exit code when no checks are foundwilliammartin commentedon Oct 17, 2024
As I think about this more, I get more and more concerned about the existing UX when it comes to checks that are not yet registered. We have special cased
0checks as an error because there is a delay between the PR being created and first party or third party checks being registered against the PR. However, this delay is equally true fornchecks. There's no way that I know of to guarantee that a slow third party hasn't yet registered a check. For example, we may have4checks that have all passed, but a slow third party has not registered the5th. This is indistinguishable from it not existing.I think that instead of a separate status code, I would like this discrepancy to be called out and explicitly opted into via a flag. That way users can clearly understand that relying on this behaviour comes with risks. @clarityflowers do you think a flag like
--succeed-on-no-checkswould work for your case, with the behaviour being that we would exit0if this flag were provided and the API returned no checks.clarityflowers commentedon Oct 17, 2024
Yeah, that would work fine!
fix: address Codex round-11 review findings
feat: pure-dev plugin marketplace with quick-dev and notion-dev (#1)
fix(manifest-forge): treat an empty required-check set as no gate in …
fix(manifest-security, manifest-forge): eval-flagged skill fixes + pr…
fix(claude): a status answer from gh pr checks no longer fails a succ…