MCPcopy Create free account
hub / github.com/cli/cli / SmartBaseRepoFunc

Function SmartBaseRepoFunc

pkg/cmd/factory/default.go:162–186  ·  view source on GitHub ↗

SmartBaseRepoFunc provides additional behaviour over BaseRepoFunc. Read the BaseRepoFunc documentation for more information on how remotes are fetched and ordered. Unlike BaseRepoFunc, instead of selecting the first remote in the list, this function will use the API to resolve repository networks,

(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

160// If more than one repo is returned from the API, we indicate to the user that they need to run `repo set-default`,
161// and return an error with no base repo.
162func SmartBaseRepoFunc(f *cmdutil.Factory) func() (ghrepo.Interface, error) {
163 return func() (ghrepo.Interface, error) {
164 httpClient, err := f.HttpClient()
165 if err != nil {
166 return nil, err
167 }
168
169 apiClient := api.NewClientFromHTTP(httpClient)
170
171 remotes, err := f.Remotes()
172 if err != nil {
173 return nil, err
174 }
175 resolvedRepos, err := ghContext.ResolveRemotesToRepos(remotes, apiClient, "")
176 if err != nil {
177 return nil, err
178 }
179 baseRepo, err := resolvedRepos.BaseRepo(f.IOStreams)
180 if err != nil {
181 return nil, err
182 }
183
184 return baseRepo, nil
185 }
186}
187
188func remotesFunc(f *cmdutil.Factory) func() (ghContext.Remotes, error) {
189 rr := &remoteResolver{

Callers 2

NewCmdRootFunction · 0.92
Test_SmartBaseRepoFunction · 0.85

Calls 3

NewClientFromHTTPFunction · 0.92
RemotesMethod · 0.65
BaseRepoMethod · 0.65

Tested by 1

Test_SmartBaseRepoFunction · 0.68