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)
| 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. |
| 152 | func 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 | |
| 178 | func remotesFunc(f *cmdutil.Factory) func() (ghContext.Remotes, error) { |
| 179 | rr := &remoteResolver{ |