diff --git a/api/queries_pr.go b/api/queries_pr.go index ad4f23644..882627055 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -1144,7 +1144,7 @@ func PullRequestReopen(client *Client, repo ghrepo.Interface, pr *PullRequest) e return err } -func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m PullRequestMergeMethod) error { +func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m PullRequestMergeMethod, body *string) error { mergeMethod := githubv4.PullRequestMergeMethodMerge switch m { case PullRequestMergeMethodRebase: @@ -1170,6 +1170,10 @@ func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m commitHeadline := githubv4.String(fmt.Sprintf("%s (#%d)", pr.Title, pr.Number)) input.CommitHeadline = &commitHeadline } + if body != nil { + commitBody := githubv4.String(*body) + input.CommitBody = &commitBody + } variables := map[string]interface{}{ "input": input, diff --git a/main b/main new file mode 100755 index 000000000..48c782755 Binary files /dev/null and b/main differ diff --git a/pkg/cmd/pr/merge/merge.go b/pkg/cmd/pr/merge/merge.go index 4cac24242..b060c7c11 100644 --- a/pkg/cmd/pr/merge/merge.go +++ b/pkg/cmd/pr/merge/merge.go @@ -31,6 +31,9 @@ type MergeOptions struct { DeleteBranch bool MergeMethod api.PullRequestMergeMethod + Body string + BodyChanged bool + IsDeleteBranchIndicated bool CanDeleteLocalBranch bool InteractiveMode bool @@ -95,6 +98,8 @@ func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Comm opts.IsDeleteBranchIndicated = cmd.Flags().Changed("delete-branch") opts.CanDeleteLocalBranch = !cmd.Flags().Changed("repo") + opts.BodyChanged = cmd.Flags().Changed("body") + if runF != nil { return runF(opts) } @@ -103,6 +108,7 @@ func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Comm } cmd.Flags().BoolVarP(&opts.DeleteBranch, "delete-branch", "d", false, "Delete the local and remote branch after merge") + cmd.Flags().StringVarP(&opts.Body, "body", "b", "", "Body for merge commit") cmd.Flags().BoolVarP(&flagMerge, "merge", "m", false, "Merge the commits with the base branch") cmd.Flags().BoolVarP(&flagRebase, "rebase", "r", false, "Rebase the commits onto the base branch") cmd.Flags().BoolVarP(&flagSquash, "squash", "s", false, "Squash the commits into one commit and merge it into the base branch") @@ -147,7 +153,12 @@ func mergeRun(opts *MergeOptions) error { } } - err = api.PullRequestMerge(apiClient, baseRepo, pr, mergeMethod) + var body *string = nil + if opts.BodyChanged { + body = &opts.Body + } + + err = api.PullRequestMerge(apiClient, baseRepo, pr, mergeMethod, body) if err != nil { return err }