MCPcopy Index your code
hub / github.com/cli/cli / submitPR

Function submitPR

pkg/cmd/pr/create/create.go:1036–1078  ·  view source on GitHub ↗
(opts CreateOptions, ctx CreateContext, state shared.IssueMetadataState, projectV1Support gh.ProjectsV1Support)

Source from the content-addressed store, hash-verified

1034}
1035
1036func 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
1080func renderPullRequestPlain(w io.Writer, params map[string]interface{}, state *shared.IssueMetadataState) error {
1081 fmt.Fprint(w, "Would have created a Pull Request with:\n")

Callers 1

createRunFunction · 0.85

Calls 11

AddMetadataToIssueParamsFunction · 0.92
CreatePullRequestFunction · 0.92
renderPullRequestTTYFunction · 0.85
renderPullRequestPlainFunction · 0.85
IsStdoutTTYMethod · 0.80
BaseRefMethod · 0.65
QualifiedHeadRefMethod · 0.65
BaseRepoMethod · 0.65
StopProgressIndicatorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected