fix(browse): resolve ambiguous decimal SHA via local git lookup#13600
Open
jfjrh2014 wants to merge 3 commits into
Open
fix(browse): resolve ambiguous decimal SHA via local git lookup#13600jfjrh2014 wants to merge 3 commits into
jfjrh2014 wants to merge 3 commits into
Conversation
When the selector argument was all decimal digits and 7+ characters long (e.g. 3096289), gh browse always treated it as an issue number even when it matched an abbreviated commit hash in the local repo. Now ambiguous selectors are checked against the local git repository: if the SHA resolves to a commit, the commit URL is opened; otherwise the existing issue-URL behavior is preserved. Fixes cli#12357 Signed-off-by: jeff <jfjrh2014@gmail.com>
|
if I'm reading your description right (didn't open code) you did not abide by the agreement between the reporter (me) and the maintainer in the issue discussion that the ref MAY be remote. |
Use the GitHub REST API to disambiguate selectors that are both valid decimal numbers and valid commit SHAs (e.g. 3096289). This handles the case where the target ref may only exist on the remote, and also works when using -R to override the repository. The # prefix still forces issue interpretation regardless. Closes cli#12357 Signed-off-by: jeff <jfjrh2014@gmail.com>
…enario 3 Clean up leftover CommitBody interface additions that are unused. The ambiguous resolution now solely uses the remote REST API approach as agreed with the maintainer in issue cli#12357. Adds test for AC scenario 3: # prefix on ambiguous decimal SHA forces issue interpretation regardless of commit existence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gh browse 309628980always opened/issues/309628980, even when the selector matched an abbreviated commit SHA in the local repository.When a selector is all decimal digits and 7+ characters long, it is ambiguous: it could be either an issue number or a shortened commit hash. Today the issue interpretation wins unconditionally.
This change adds a local-git lookup on the ambiguous path: if a matching commit exists, the commit URL is opened. Otherwise the existing issue-URL behavior is preserved.
Fixes #12357
Changes
pkg/cmd/browse/browse.go:parseSectionnow consults the local git repo for ambiguous (numeric, 7+ char) selectors. AddsCommitBodyto thegitClientinterface.pkg/cmd/browse/browse_test.go: covers both directions — ambiguous SHA that exists locally → commit URL; ambiguous SHA that does not → issue URL.Notes
remoteGitClient.CommitBodyreturns an error so remote repos preserve the previous behavior (no GraphQL endpoint to validate an arbitrary abbreviated SHA).