Skip to content

Commit d92c80b

Browse files
committed
just swap BaseRepo implementation
1 parent 086fb48 commit d92c80b

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

command/root.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,6 @@ func init() {
9090
}
9191
return httpClient(token), nil
9292
},
93-
ResolvedBaseRepo: func(client *http.Client) (ghrepo.Interface, error) {
94-
// TODO this may be abandoned when we stop trying to be magical about picking base repos for
95-
// users. We can merge this with BaseRepo at that point.
96-
apiClient := api.NewClientFromHTTP(client)
97-
ctx := context.New()
98-
remotes, err := ctx.Remotes()
99-
if err != nil {
100-
return nil, err
101-
}
102-
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "")
103-
if err != nil {
104-
return nil, err
105-
}
106-
baseRepo, err := repoContext.BaseRepo()
107-
if err != nil {
108-
return nil, err
109-
}
110-
111-
return baseRepo, nil
112-
},
11393
BaseRepo: func() (ghrepo.Interface, error) {
11494
// TODO: decouple from `context`
11595
ctx := context.New()

pkg/cmd/repo/view/view.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/MakeNowJust/heredoc"
1111
"github.com/cli/cli/api"
12+
"github.com/cli/cli/context"
1213
"github.com/cli/cli/internal/ghrepo"
1314
"github.com/cli/cli/pkg/cmdutil"
1415
"github.com/cli/cli/pkg/iostreams"
@@ -17,19 +18,42 @@ import (
1718
)
1819

1920
type ViewOptions struct {
20-
HttpClient func() (*http.Client, error)
21-
IO *iostreams.IOStreams
22-
ResolvedBaseRepo func(*http.Client) (ghrepo.Interface, error)
21+
HttpClient func() (*http.Client, error)
22+
IO *iostreams.IOStreams
23+
BaseRepo func() (ghrepo.Interface, error)
2324

2425
RepoArg string
2526
Web bool
2627
}
2728

2829
func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
2930
opts := ViewOptions{
30-
IO: f.IOStreams,
31-
HttpClient: f.HttpClient,
32-
ResolvedBaseRepo: f.ResolvedBaseRepo,
31+
IO: f.IOStreams,
32+
HttpClient: f.HttpClient,
33+
BaseRepo: func() (ghrepo.Interface, error) {
34+
httpClient, err := f.HttpClient()
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
apiClient := api.NewClientFromHTTP(httpClient)
40+
41+
ctx := context.New()
42+
remotes, err := ctx.Remotes()
43+
if err != nil {
44+
return nil, err
45+
}
46+
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "")
47+
if err != nil {
48+
return nil, err
49+
}
50+
baseRepo, err := repoContext.BaseRepo()
51+
if err != nil {
52+
return nil, err
53+
}
54+
55+
return baseRepo, nil
56+
},
3357
}
3458

3559
cmd := &cobra.Command{
@@ -66,7 +90,7 @@ func viewRun(opts *ViewOptions) error {
6690
var toView ghrepo.Interface
6791
if opts.RepoArg == "" {
6892
var err error
69-
toView, err = opts.ResolvedBaseRepo(httpClient)
93+
toView, err = opts.BaseRepo()
7094
if err != nil {
7195
return err
7296
}

pkg/cmd/repo/view/view_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func Test_RepoView_Web(t *testing.T) {
113113
HttpClient: func() (*http.Client, error) {
114114
return &http.Client{Transport: reg}, nil
115115
},
116-
ResolvedBaseRepo: func(_ *http.Client) (ghrepo.Interface, error) {
116+
BaseRepo: func() (ghrepo.Interface, error) {
117117
return ghrepo.New("OWNER", "REPO"), nil
118118
},
119119
}
@@ -225,7 +225,7 @@ func Test_ViewRun(t *testing.T) {
225225
tt.repoName = "OWNER/REPO"
226226
}
227227

228-
tt.opts.ResolvedBaseRepo = func(_ *http.Client) (ghrepo.Interface, error) {
228+
tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
229229
repo, _ := ghrepo.FromFullName(tt.repoName)
230230
return repo, nil
231231
}
@@ -312,7 +312,7 @@ func Test_ViewRun_NonMarkdownReadme(t *testing.T) {
312312
HttpClient: func() (*http.Client, error) {
313313
return &http.Client{Transport: reg}, nil
314314
},
315-
ResolvedBaseRepo: func(_ *http.Client) (ghrepo.Interface, error) {
315+
BaseRepo: func() (ghrepo.Interface, error) {
316316
return ghrepo.New("OWNER", "REPO"), nil
317317
},
318318
}
@@ -378,7 +378,7 @@ func Test_ViewRun_NoReadme(t *testing.T) {
378378
HttpClient: func() (*http.Client, error) {
379379
return &http.Client{Transport: reg}, nil
380380
},
381-
ResolvedBaseRepo: func(_ *http.Client) (ghrepo.Interface, error) {
381+
BaseRepo: func() (ghrepo.Interface, error) {
382382
return ghrepo.New("OWNER", "REPO"), nil
383383
},
384384
}
@@ -448,7 +448,7 @@ func Test_ViewRun_NoDescription(t *testing.T) {
448448
HttpClient: func() (*http.Client, error) {
449449
return &http.Client{Transport: reg}, nil
450450
},
451-
ResolvedBaseRepo: func(_ *http.Client) (ghrepo.Interface, error) {
451+
BaseRepo: func() (ghrepo.Interface, error) {
452452
return ghrepo.New("OWNER", "REPO"), nil
453453
},
454454
}

pkg/cmdutil/factory.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
)
99

1010
type Factory struct {
11-
IOStreams *iostreams.IOStreams
12-
HttpClient func() (*http.Client, error)
13-
ResolvedBaseRepo func(*http.Client) (ghrepo.Interface, error)
14-
BaseRepo func() (ghrepo.Interface, error)
11+
IOStreams *iostreams.IOStreams
12+
HttpClient func() (*http.Client, error)
13+
BaseRepo func() (ghrepo.Interface, error)
1514
}

0 commit comments

Comments
 (0)