(ctx context.Context, ch *cmdutil.Helper, opts *DeployOpts)
| 70 | } |
| 71 | |
| 72 | func ConnectGithubFlow(ctx context.Context, ch *cmdutil.Helper, opts *DeployOpts) error { |
| 73 | // Set a default org for the user if necessary |
| 74 | // (If user is not in an org, we'll create one based on their Github account later in the flow.) |
| 75 | // TODO : similar to UI workflow create a org taking user input |
| 76 | if ch.Org == "" { |
| 77 | if !ch.Interactive { |
| 78 | return fmt.Errorf("`org` must be set to use the GitHub connect flow in non-interactive mode") |
| 79 | } |
| 80 | if err := org.SetDefaultOrg(ctx, ch); err != nil { |
| 81 | return err |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | err := opts.ValidateAndApplyDefaults(ctx, ch) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | localGitPath := opts.GitPath |
| 91 | localProjectPath := opts.LocalProjectPath() |
| 92 | |
| 93 | if opts.pushToProject != nil { |
| 94 | return redeployProject(ctx, ch, opts) |
| 95 | } |
| 96 | |
| 97 | if opts.remoteURL == "" { |
| 98 | // first check if user wants to create a github repo |
| 99 | ch.Print("No git remote was found.\n") |
| 100 | if err := cmdutil.ConfirmPrompt("Do you want to create a Github repository?", true); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | if err := createGithubRepoFlow(ctx, ch, localGitPath); err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | // In the rest of the flow we still check for the github access. |
| 109 | // It just adds some delay and no user action should be required and handles any improbable edge case where we don't have access to newly created repository. |
| 110 | // Also keeps the code clean. |
| 111 | remote, err := gitutil.ExtractGitRemote(localGitPath, opts.RemoteName, false) |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | opts.remoteURL, err = remote.Github() |
| 116 | opts.RemoteName = remote.Name |
| 117 | if err != nil { |
| 118 | return err |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Error if the repository is not in sync with the remote |
| 123 | ok, err := repoInSyncFlow(ch, localGitPath, opts.SubPath, opts.RemoteName) |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | if !ok { |
| 128 | ch.PrintfBold("You can run `rill deploy` again when you have pushed your local changes to the remote.\n") |
| 129 | return nil |
no test coverage detected