reformatted spacing and final touches

This commit is contained in:
bchadwic 2021-06-14 22:31:29 -07:00
parent cac372d017
commit 679d396c8d
2 changed files with 8 additions and 11 deletions

View file

@ -105,7 +105,6 @@ func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Co
}
func runBrowse(opts *BrowseOptions) error {
baseRepo, err := opts.BaseRepo()
if err != nil {
return fmt.Errorf("unable to determine base repository: %w\nUse 'gh browse --help' for more information about browse\n", err)
@ -115,19 +114,15 @@ func runBrowse(opts *BrowseOptions) error {
if err != nil {
return fmt.Errorf("unable to create an http client: %w\nUse 'gh browse --help' for more information about browse\n", err)
}
url := ghrepo.GenerateRepoURL(baseRepo, "")
if opts.SelectorArg == "" {
if opts.ProjectsFlag {
url += "/projects"
}
if opts.SettingsFlag {
url += "/settings"
}
if opts.WikiFlag {
url += "/wiki"
}
@ -161,6 +156,7 @@ func runBrowse(opts *BrowseOptions) error {
}
}
}
err = opts.Browser.Browse(url)
if opts.IO.IsStdoutTTY() && err == nil {
fmt.Fprintf(opts.IO.Out, "now opening %s in browser\n", url)
@ -168,6 +164,7 @@ func runBrowse(opts *BrowseOptions) error {
return err
}
func parseFileArg(fileArg string) ([]string, error) {
arr := strings.Split(fileArg, ":")
if len(arr) > 2 {
@ -176,7 +173,6 @@ func parseFileArg(fileArg string) ([]string, error) {
if len(arr) > 1 && !isNumber(arr[1]) {
return arr, fmt.Errorf("invalid line number after colon\nUse 'gh browse --help' for more information about browse\n")
}
return arr, nil
}

View file

@ -185,8 +185,8 @@ func Test_runBrowse(t *testing.T) {
opts: BrowseOptions{
Branch: "trunk",
},
baseRepo: ghrepo.New("jlsestak", "vegan"),
expectedURL: "https://github.com/jlsestak/vegan/tree/trunk/",
baseRepo: ghrepo.New("jlsestak", "CouldNotThinkOfARepoName"),
expectedURL: "https://github.com/jlsestak/CouldNotThinkOfARepoName/tree/trunk/",
},
{
name: "branch flag with file",
@ -225,13 +225,14 @@ func Test_runBrowse(t *testing.T) {
expectedURL: "https://github.com/ken/grc/issues/217",
},
{
name: "opening branch",
name: "opening branch file with line number",
opts: BrowseOptions{
Branch: "first-browse-pull",
Branch: "first-browse-pull",
SelectorArg: "browse.go:32",
},
baseRepo: ghrepo.New("github", "ThankYouGitHub"),
wantsErr: false,
expectedURL: "https://github.com/github/ThankYouGitHub/tree/first-browse-pull/",
expectedURL: "https://github.com/github/ThankYouGitHub/tree/first-browse-pull/browse.go#L32",
},
}