Skip to content

Commit d77a8c2

Browse files
committed
Scope pr merge commit headline to only squash method
1 parent cab0e0f commit d77a8c2

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

api/queries_pr.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,18 @@ func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m
981981
} `graphql:"mergePullRequest(input: $input)"`
982982
}
983983

984-
commitHeadline := githubv4.String(fmt.Sprintf("%s (#%d)", pr.Title, pr.Number))
984+
input := githubv4.MergePullRequestInput{
985+
PullRequestID: pr.ID,
986+
MergeMethod: &mergeMethod,
987+
}
988+
989+
if m == PullRequestMergeMethodSquash {
990+
commitHeadline := githubv4.String(fmt.Sprintf("%s (#%d)", pr.Title, pr.Number))
991+
input.CommitHeadline = &commitHeadline
992+
}
993+
985994
variables := map[string]interface{}{
986-
"input": githubv4.MergePullRequestInput{
987-
PullRequestID: pr.ID,
988-
MergeMethod: &mergeMethod,
989-
CommitHeadline: &commitHeadline,
990-
},
995+
"input": input,
991996
}
992997

993998
gql := graphQLClient(client.http, repo.RepoHost())

pkg/cmd/pr/merge/merge_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func TestPrMerge(t *testing.T) {
189189
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
190190
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
191191
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
192+
assert.NotContains(t, input, "commitHeadline")
192193
}))
193194
http.Register(
194195
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -234,6 +235,7 @@ func TestPrMerge_nontty(t *testing.T) {
234235
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
235236
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
236237
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
238+
assert.NotContains(t, input, "commitHeadline")
237239
}))
238240
http.Register(
239241
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -276,6 +278,7 @@ func TestPrMerge_withRepoFlag(t *testing.T) {
276278
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
277279
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
278280
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
281+
assert.NotContains(t, input, "commitHeadline")
279282
}))
280283
http.Register(
281284
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -310,6 +313,7 @@ func TestPrMerge_deleteBranch(t *testing.T) {
310313
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
311314
assert.Equal(t, "PR_10", input["pullRequestId"].(string))
312315
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
316+
assert.NotContains(t, input, "commitHeadline")
313317
}))
314318
http.Register(
315319
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -344,6 +348,7 @@ func TestPrMerge_deleteNonCurrentBranch(t *testing.T) {
344348
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
345349
assert.Equal(t, "PR_10", input["pullRequestId"].(string))
346350
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
351+
assert.NotContains(t, input, "commitHeadline")
347352
}))
348353
http.Register(
349354
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -376,6 +381,7 @@ func TestPrMerge_noPrNumberGiven(t *testing.T) {
376381
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
377382
assert.Equal(t, "PR_10", input["pullRequestId"].(string))
378383
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
384+
assert.NotContains(t, input, "commitHeadline")
379385
}))
380386
http.Register(
381387
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -421,6 +427,7 @@ func TestPrMerge_rebase(t *testing.T) {
421427
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
422428
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
423429
assert.Equal(t, "REBASE", input["mergeMethod"].(string))
430+
assert.NotContains(t, input, "commitHeadline")
424431
}))
425432
http.Register(
426433
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -465,6 +472,7 @@ func TestPrMerge_squash(t *testing.T) {
465472
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
466473
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
467474
assert.Equal(t, "SQUASH", input["mergeMethod"].(string))
475+
assert.Equal(t, "The title of the PR (#3)", input["commitHeadline"].(string))
468476
}))
469477
http.Register(
470478
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
@@ -533,6 +541,7 @@ func TestPRMerge_interactive(t *testing.T) {
533541
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
534542
assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
535543
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
544+
assert.NotContains(t, input, "commitHeadline")
536545
}))
537546
http.Register(
538547
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),

0 commit comments

Comments
 (0)