Skip to content

gh pr checks uses a unique exit code when no checks are found - #9691

Closed
BagToad wants to merge 6 commits into
trunkfrom
kw-cli-9682-exit-0-for-no-check-results
Closed

BagToad wants to merge 6 commits into
trunkfrom
kw-cli-9682-exit-0-for-no-check-results

Conversation

@BagToad

@BagToad BagToad commented Oct 1, 2024 •

Copy link
Copy Markdown
Member

This PR proposes changes to gh pr checks and gh pr checks --required to both exit 16 when no results are found.

Demo

❯ ./bin/gh pr checks 14 -R owner/repo --required
no required checks reported on the 'branch-name' branch

❯ echo $?
16
❯ ./bin/gh pr checks 1 -R "owner/name"           
no checks reported on the 'branch-name' branch

❯ echo $?
16

Fixes #9682

@BagToad
BagToad requested a review from a team as a code owner October 1, 2024 22:33
@BagToad
BagToad requested a review from williammartin October 1, 2024 22:33
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Oct 1, 2024

@williammartin williammartin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BagToad I pushed a commit on top of this that I would want if we do merge this.

I have some concerns about merging this in #9682 (comment)

@jtmcg jtmcg removed the external pull request originating outside of the CLI core team label Oct 2, 2024
@BagToad
BagToad marked this pull request as draft October 7, 2024 22:34
@BagToad BagToad changed the title Make gh pr checks exit 0 when no checks are found gh pr checks uses a unique exit code when no checks are found Oct 7, 2024
Comment thread cmd/gh/main.go
exitCancel exitCode = 2
exitAuth exitCode = 4
exitPending exitCode = 8
exitUnkown exitCode = 16

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly concerned about what exit code to use for this situation, so happy to hear others' thoughts about it if you think we could use something better.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even one of the existing exit codes. Though I will say, making a unique exit code for an "unknown results" situation does make the most sense to me. Willing to be convinced otherwise though!

Comment thread pkg/cmdutil/errors.go
Comment on lines +71 to +82

type UnknownResultsError struct {
message string
}

func (e UnknownResultsError) Error() string {
return e.message
}

func NewUnknownResultsError(message string) UnknownResultsError {
return UnknownResultsError{message: message}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to call this thing UnknownResultsError because it seemed the most appropriate with the problem raised in #9682 (comment):

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”.

The way I read this is that we don't know, and so it would make sense to exit with something new and unique that is specifically about situations where we don't know.

@BagToad
BagToad marked this pull request as ready for review October 7, 2024 23:05
@BagToad
BagToad requested a review from williammartin October 7, 2024 23:05
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Oct 7, 2024
@BagToad BagToad removed the external pull request originating outside of the CLI core team label Oct 7, 2024
@BagToad

BagToad commented Oct 7, 2024 •

Copy link
Copy Markdown
Member Author

@williammartin this is ready for another look adjusted with the changes discussed in #9682

@BagToad

BagToad commented Oct 17, 2024

Copy link
Copy Markdown
Member Author

Closing in favor of an alternative implementation to be decided later: #9682 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh pr checks <pr> --required should not fail when there are no required checks

4 participants