| 22 | type remotesFn func() (ghContext.Remotes, error) |
| 23 | |
| 24 | func PromptWhenAmbiguousBaseRepoFunc(baseRepoFn baseRepoFn, ios *iostreams.IOStreams, prompter prompter.Prompter) baseRepoFn { |
| 25 | return func() (ghrepo.Interface, error) { |
| 26 | baseRepo, err := baseRepoFn() |
| 27 | if err != nil { |
| 28 | var ambiguousBaseRepoErr AmbiguousBaseRepoError |
| 29 | if !errors.As(err, &ambiguousBaseRepoErr) { |
| 30 | return nil, err |
| 31 | } |
| 32 | |
| 33 | baseRepoOptions := make([]string, len(ambiguousBaseRepoErr.Remotes)) |
| 34 | for i, remote := range ambiguousBaseRepoErr.Remotes { |
| 35 | baseRepoOptions[i] = ghrepo.FullName(remote) |
| 36 | } |
| 37 | |
| 38 | fmt.Fprintf(ios.Out, "%s Multiple remotes detected. Due to the sensitive nature of secrets, requiring disambiguation.\n", ios.ColorScheme().WarningIcon()) |
| 39 | selectedBaseRepo, err := prompter.Select("Select a repo", baseRepoOptions[0], baseRepoOptions) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | selectedRepo, err := ghrepo.FromFullName(baseRepoOptions[selectedBaseRepo]) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | return selectedRepo, nil |
| 50 | } |
| 51 | |
| 52 | return baseRepo, nil |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // RequireNoAmbiguityBaseRepoFunc returns a function to resolve the base repo, ensuring that |
| 57 | // there was only one option, regardless of whether the base repo had been set. |