Return error on no-browser option if repo don't exists
This commit is contained in:
parent
c0855a3e61
commit
aa0f2de885
4 changed files with 114 additions and 1 deletions
|
|
@ -180,7 +180,19 @@ func runBrowse(opts *BrowseOptions) error {
|
|||
url := ghrepo.GenerateRepoURL(baseRepo, "%s", section)
|
||||
|
||||
if opts.NoBrowserFlag {
|
||||
_, err := fmt.Fprintln(opts.IO.Out, url)
|
||||
client, err := opts.HttpClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
exist, err := api.RepoExists(api.NewClientFromHTTP(client), baseRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
return fmt.Errorf("%s doesn't exists", text.DisplayURL(url))
|
||||
}
|
||||
_, err = fmt.Fprintln(opts.IO.Out, url)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ func Test_runBrowse(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
opts BrowseOptions
|
||||
httpStub func(*httpmock.Registry)
|
||||
baseRepo ghrepo.Interface
|
||||
defaultBranch string
|
||||
expectedURL string
|
||||
|
|
@ -432,6 +433,12 @@ func Test_runBrowse(t *testing.T) {
|
|||
SelectorArg: "init.rb:6",
|
||||
NoBrowserFlag: true,
|
||||
},
|
||||
httpStub: func(r *httpmock.Registry) {
|
||||
r.Register(
|
||||
httpmock.REST("HEAD", "repos/mislav/will_paginate"),
|
||||
httpmock.StringResponse("{}"),
|
||||
)
|
||||
},
|
||||
baseRepo: ghrepo.New("mislav", "will_paginate"),
|
||||
wantsErr: false,
|
||||
expectedURL: "https://github.com/mislav/will_paginate/blob/3-0-stable/init.rb?plain=1#L6",
|
||||
|
|
@ -556,6 +563,10 @@ func Test_runBrowse(t *testing.T) {
|
|||
reg.StubRepoInfoResponse(tt.baseRepo.RepoOwner(), tt.baseRepo.RepoName(), tt.defaultBranch)
|
||||
}
|
||||
|
||||
if tt.httpStub != nil {
|
||||
tt.httpStub(®)
|
||||
}
|
||||
|
||||
opts := tt.opts
|
||||
opts.IO = ios
|
||||
opts.BaseRepo = func() (ghrepo.Interface, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue