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

Function SmartBaseRepoFunc

pkg/cmd/factory/default.go:161–185  ·  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

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