Skip to content

fix(browse): disambiguate numeric short SHAs from issue/PR numbers#12684

Open
amirHdev wants to merge 1 commit intocli:trunkfrom
amirHdev:fix-browse-numeric-short-sha-disambiguation
Open

fix(browse): disambiguate numeric short SHAs from issue/PR numbers#12684
amirHdev wants to merge 1 commit intocli:trunkfrom
amirHdev:fix-browse-numeric-short-sha-disambiguation

Conversation

@amirHdev
Copy link

Summary

Fix gh browse selector disambiguation for numeric-only short SHAs.

Today, if the selector arg is numeric (e.g. 309628980), gh browse treats it as an issue/PR number before considering commit refs. This causes decimal-only short SHAs to resolve to issues/<n> instead of commit/<sha>.

This change updates browse to disambiguate in the ambiguous case:

  • if selector is both numeric and commit-like, check whether it resolves to a commit in the target repo
  • if commit exists, open the commit URL
  • otherwise, fall back to issue URL behavior

Changes

  • Updated parseSection in pkg/cmd/browse/browse.go to validate ambiguous numeric+commit-like selectors via API.
  • Added commitRefExists helper that calls:
    • GET /repos/{owner}/{repo}/commits/{ref}
    • treats 404/422 as “commit not found”
  • Added tests in pkg/cmd/browse/browse_test.go for:
    • numeric short SHA that exists as commit -> commit URL
    • numeric short SHA not found as commit -> issue URL

Testing

  • go test ./pkg/cmd/browse
  • Added targeted cases under Test_runBrowse for ambiguous numeric selectors.

Fixes #12357

… refs

When a selector arg is both numeric and commit-like, browse now validates whether it resolves to a commit in the target repo before defaulting to an issue URL.

This fixes cases like decimal-only short SHAs being interpreted as issue numbers.

Add tests for both commit-found and commit-not-found paths.
@amirHdev amirHdev requested a review from a team as a code owner February 14, 2026 16:20
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 14, 2026
@github-actions
Copy link

Thank you for your pull request! 🎉

This PR appears to fix the following issues that are not labeled with help wanted Contributions welcome :

As outlined in our Contributing Guidelines, we expect that PRs are only created for issues that have been labeled help wanted.

While we appreciate your initiative, please note that:

  • PRs for non-help wanted issues may not be reviewed immediately as they might not align with our current priorities
  • The issue might already be assigned to a team member or planned for a specific release
  • We may need to close this PR. For example, if it conflicts with ongoing work or architectural decisions

What happens next:

  • Our team will review this PR and the associated issues
  • We may add the help wanted label to the issues, if appropriate, and review this pull request
  • In some cases, we may need to close the PR. For example, if it doesn't fit our current roadmap

Thank you for your understanding and contribution to the project! 🙏

This comment was automatically generated by cliAutomation.

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

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh browse mistakes short hash for issue/pr number

2 participants