MCPcopy
hub / github.com/cli/cli / SmartBaseRepoFunc

Function SmartBaseRepoFunc

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

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