Merge pull request #7038 from yanskun/feat/add-open-num-commit-hash

Made it possible to do open num only commit hash with Browse Command
This commit is contained in:
Nate Smith 2023-03-01 17:38:34 -06:00 committed by GitHub
commit fe78331342
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -174,7 +174,7 @@ func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error
}
}
if isNumber(opts.SelectorArg) {
if !opts.CommitFlag && isNumber(opts.SelectorArg) {
return fmt.Sprintf("issues/%s", strings.TrimPrefix(opts.SelectorArg, "#")), nil
}

View file

@ -123,6 +123,15 @@ func TestNewCmdBrowse(t *testing.T) {
},
wantsErr: false,
},
{
name: "commit hash flag",
cli: "-c 123",
wants: BrowseOptions{
CommitFlag: true,
SelectorArg: "123",
},
wantsErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -395,6 +404,17 @@ func Test_runBrowse(t *testing.T) {
wantsErr: false,
expectedURL: "https://github.com/vilmibm/gh-user-status/tree/6f1a2405cace1633d89a79c74c65f22fe78f9659/main.go",
},
{
name: "open number only commit hash",
opts: BrowseOptions{
CommitFlag: true,
SelectorArg: "1234567890",
GitClient: &testGitClient{},
},
baseRepo: ghrepo.New("yanskun", "ILoveGitHub"),
wantsErr: false,
expectedURL: "https://github.com/yanskun/ILoveGitHub/commit/1234567890",
},
{
name: "relative path from browse_test.go",
opts: BrowseOptions{