Merge pull request #3809 from cli/fork-test-cleanup

fork tests cleanup
This commit is contained in:
Nate Smith 2021-06-11 11:31:33 -05:00 committed by GitHub
commit aecfc01e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 428 additions and 569 deletions

View file

@ -22,12 +22,15 @@ import (
"github.com/spf13/pflag"
)
const defaultRemoteName = "origin"
type ForkOptions struct {
HttpClient func() (*http.Client, error)
Config func() (config.Config, error)
IO *iostreams.IOStreams
BaseRepo func() (ghrepo.Interface, error)
Remotes func() (context.Remotes, error)
Since func(time.Time) time.Duration
GitArgs []string
Repository string
@ -40,9 +43,9 @@ type ForkOptions struct {
Rename bool
}
var Since = func(t time.Time) time.Duration {
return time.Since(t)
}
// TODO warn about useless flags (--remote, --remote-name) when running from outside a repository
// TODO output over STDOUT not STDERR
// TODO remote-name has no effect on its own; error that or change behavior
func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Command {
opts := &ForkOptions{
@ -51,6 +54,7 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
Config: f.Config,
BaseRepo: f.BaseRepo,
Remotes: f.Remotes,
Since: time.Since,
}
cmd := &cobra.Command{
@ -110,7 +114,7 @@ Additional 'git clone' flags can be passed in by listing them after '--'.`,
cmd.Flags().BoolVar(&opts.Clone, "clone", false, "Clone the fork {true|false}")
cmd.Flags().BoolVar(&opts.Remote, "remote", false, "Add remote for fork {true|false}")
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", "origin", "Specify a name for a fork's new remote.")
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", defaultRemoteName, "Specify a name for a fork's new remote.")
cmd.Flags().StringVar(&opts.Organization, "org", "", "Create the fork in an organization")
return cmd
@ -182,7 +186,7 @@ func forkRun(opts *ForkOptions) error {
// returns the fork repo data even if it already exists -- with no change in status code or
// anything. We thus check the created time to see if the repo is brand new or not; if it's not,
// we assume the fork already existed and report an error.
createdAgo := Since(forkedRepo.CreatedAt)
createdAgo := opts.Since(forkedRepo.CreatedAt)
if createdAgo > time.Minute {
if connectedToTerminal {
fmt.Fprintf(stderr, "%s %s %s\n",

File diff suppressed because it is too large Load diff

View file

@ -18,7 +18,7 @@ var Confirm = func(prompt string, result *bool) error {
Message: prompt,
Default: true,
}
return survey.AskOne(p, result)
return SurveyAskOne(p, result)
}
var SurveyAskOne = func(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error {