(opts CreateOptions, ctx CreateContext, state shared.IssueMetadataState, projectV1Support gh.ProjectsV1Support)
| 1034 | } |
| 1035 | |
| 1036 | func submitPR(opts CreateOptions, ctx CreateContext, state shared.IssueMetadataState, projectV1Support gh.ProjectsV1Support) error { |
| 1037 | client := ctx.Client |
| 1038 | |
| 1039 | params := map[string]interface{}{ |
| 1040 | "title": state.Title, |
| 1041 | "body": state.Body, |
| 1042 | "draft": state.Draft, |
| 1043 | "baseRefName": ctx.PRRefs.BaseRef(), |
| 1044 | "headRefName": ctx.PRRefs.QualifiedHeadRef(), |
| 1045 | "maintainerCanModify": opts.MaintainerCanModify, |
| 1046 | } |
| 1047 | |
| 1048 | if params["title"] == "" { |
| 1049 | return errors.New("pull request title must not be blank") |
| 1050 | } |
| 1051 | |
| 1052 | err := shared.AddMetadataToIssueParams(client, ctx.PRRefs.BaseRepo(), params, &state, projectV1Support) |
| 1053 | if err != nil { |
| 1054 | return err |
| 1055 | } |
| 1056 | |
| 1057 | if opts.DryRun { |
| 1058 | if opts.IO.IsStdoutTTY() { |
| 1059 | return renderPullRequestTTY(opts.IO, params, &state) |
| 1060 | } else { |
| 1061 | return renderPullRequestPlain(opts.IO.Out, params, &state) |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | opts.IO.StartProgressIndicator() |
| 1066 | pr, err := api.CreatePullRequest(client, ctx.PRRefs.BaseRepo(), params) |
| 1067 | opts.IO.StopProgressIndicator() |
| 1068 | if pr != nil { |
| 1069 | fmt.Fprintln(opts.IO.Out, pr.URL) |
| 1070 | } |
| 1071 | if err != nil { |
| 1072 | if pr != nil { |
| 1073 | return fmt.Errorf("pull request update failed: %w", err) |
| 1074 | } |
| 1075 | return fmt.Errorf("pull request create failed: %w", err) |
| 1076 | } |
| 1077 | return nil |
| 1078 | } |
| 1079 | |
| 1080 | func renderPullRequestPlain(w io.Writer, params map[string]interface{}, state *shared.IssueMetadataState) error { |
| 1081 | fmt.Fprint(w, "Would have created a Pull Request with:\n") |
no test coverage detected