Skip to content

Commit 74614b1

Browse files
author
Nate Smith
authored
Merge pull request cli#1627 from giacomoalbe/add-commit-headline-to-pr-merge
Add PR Title to CommitHeadline during merge PR
2 parents c2d7cbf + d77a8c2 commit 74614b1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

api/queries_pr.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,18 @@ func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m
10371037
} `graphql:"mergePullRequest(input: $input)"`
10381038
}
10391039

1040+
input := githubv4.MergePullRequestInput{
1041+
PullRequestID: pr.ID,
1042+
MergeMethod: &mergeMethod,
1043+
}
1044+
1045+
if m == PullRequestMergeMethodSquash {
1046+
commitHeadline := githubv4.String(fmt.Sprintf("%s (#%d)", pr.Title, pr.Number))
1047+
input.CommitHeadline = &commitHeadline
1048+
}
1049+
10401050
variables := map[string]interface{}{
1041-
"input": githubv4.MergePullRequestInput{
1042-
PullRequestID: pr.ID,
1043-
MergeMethod: &mergeMethod,
1044-
},
1051+
"input": input,
10451052
}
10461053

10471054
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)