feat: add open num hash to browse command

This commit is contained in:
Naoya Yasuda 2023-02-25 23:22:39 +09:00
parent 57c73e8239
commit 19788459cd
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{