Fix browse issue with leading hashtag (#6144)

This commit is contained in:
Natthakit Susanthitanon 2022-08-29 17:58:46 +07:00 committed by GitHub
parent 2fc0ffd0be
commit ac036c1c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -167,7 +167,7 @@ func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error
}
if isNumber(opts.SelectorArg) {
return fmt.Sprintf("issues/%s", opts.SelectorArg), nil
return fmt.Sprintf("issues/%s", strings.TrimPrefix(opts.SelectorArg, "#")), nil
}
if isCommit(opts.SelectorArg) {
@ -253,7 +253,7 @@ func parseFile(opts BrowseOptions, f string) (p string, start int, end int, err
}
func isNumber(arg string) bool {
_, err := strconv.Atoi(arg)
_, err := strconv.Atoi(strings.TrimPrefix(arg, "#"))
return err == nil
}

View file

@ -222,6 +222,14 @@ func Test_runBrowse(t *testing.T) {
baseRepo: ghrepo.New("kevin", "MinTy"),
expectedURL: "https://github.com/kevin/MinTy/issues/217",
},
{
name: "issue with hashtag argument",
opts: BrowseOptions{
SelectorArg: "#217",
},
baseRepo: ghrepo.New("kevin", "MinTy"),
expectedURL: "https://github.com/kevin/MinTy/issues/217",
},
{
name: "branch flag",
opts: BrowseOptions{