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

Function SmartBaseRepoFunc

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

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