X Tutup
Skip to content

Commit bc7f733

Browse files
committed
Add body argument to pr merge command.
1 parent b5366c6 commit bc7f733

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

api/queries_pr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ func PullRequestReopen(client *Client, repo ghrepo.Interface, pr *PullRequest) e
11441144
return err
11451145
}
11461146

1147-
func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m PullRequestMergeMethod) error {
1147+
func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m PullRequestMergeMethod, body *string) error {
11481148
mergeMethod := githubv4.PullRequestMergeMethodMerge
11491149
switch m {
11501150
case PullRequestMergeMethodRebase:
@@ -1170,6 +1170,10 @@ func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m
11701170
commitHeadline := githubv4.String(fmt.Sprintf("%s (#%d)", pr.Title, pr.Number))
11711171
input.CommitHeadline = &commitHeadline
11721172
}
1173+
if body != nil {
1174+
commitBody := githubv4.String(*body)
1175+
input.CommitBody = &commitBody
1176+
}
11731177

11741178
variables := map[string]interface{}{
11751179
"input": input,

main

20 MB
Binary file not shown.

pkg/cmd/pr/merge/merge.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type MergeOptions struct {
3131
DeleteBranch bool
3232
MergeMethod api.PullRequestMergeMethod
3333

34+
Body string
35+
BodyChanged bool
36+
3437
IsDeleteBranchIndicated bool
3538
CanDeleteLocalBranch bool
3639
InteractiveMode bool
@@ -95,6 +98,8 @@ func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Comm
9598
opts.IsDeleteBranchIndicated = cmd.Flags().Changed("delete-branch")
9699
opts.CanDeleteLocalBranch = !cmd.Flags().Changed("repo")
97100

101+
opts.BodyChanged = cmd.Flags().Changed("body")
102+
98103
if runF != nil {
99104
return runF(opts)
100105
}
@@ -103,6 +108,7 @@ func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Comm
103108
}
104109

105110
cmd.Flags().BoolVarP(&opts.DeleteBranch, "delete-branch", "d", false, "Delete the local and remote branch after merge")
111+
cmd.Flags().StringVarP(&opts.Body, "body", "b", "", "Body for merge commit")
106112
cmd.Flags().BoolVarP(&flagMerge, "merge", "m", false, "Merge the commits with the base branch")
107113
cmd.Flags().BoolVarP(&flagRebase, "rebase", "r", false, "Rebase the commits onto the base branch")
108114
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 {
147153
}
148154
}
149155

150-
err = api.PullRequestMerge(apiClient, baseRepo, pr, mergeMethod)
156+
var body *string = nil
157+
if opts.BodyChanged {
158+
body = &opts.Body
159+
}
160+
161+
err = api.PullRequestMerge(apiClient, baseRepo, pr, mergeMethod, body)
151162
if err != nil {
152163
return err
153164
}

0 commit comments

Comments
 (0)
X Tutup