Skip to content

Commit 09a92c6

Browse files
authored
Merge pull request cli#3688 from cli/pr-merge-fix
Fix `pr merge` with GHE < 3.0
2 parents ca04e21 + 0208620 commit 09a92c6

File tree

5 files changed

+9
-47
lines changed

5 files changed

+9
-47
lines changed

api/query_builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ func PullRequestGraphQL(fields []string) string {
208208
q = append(q, prFiles)
209209
case "commits":
210210
q = append(q, prCommits)
211+
case "lastCommit": // pseudo-field
212+
q = append(q, `commits(last:1){nodes{commit{oid}}}`)
211213
case "commitsCount": // pseudo-field
212214
q = append(q, `commits{totalCount}`)
213215
case "statusCheckRollup":

pkg/cmd/pr/merge/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func mergeRun(opts *MergeOptions) error {
156156

157157
findOptions := shared.FindOptions{
158158
Selector: opts.SelectorArg,
159-
Fields: []string{"id", "number", "state", "title", "commits", "mergeable", "headRepositoryOwner", "headRefName"},
159+
Fields: []string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"},
160160
}
161161
pr, baseRepo, err := opts.Finder.Find(findOptions)
162162
if err != nil {

pkg/cmd/pr/merge/merge_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,8 @@ func Test_nonDivergingPullRequest(t *testing.T) {
464464
}
465465
stubCommit(pr, "COMMITSHA1")
466466

467-
shared.RunCommandFinder(
468-
"",
469-
pr,
470-
baseRepo("OWNER", "REPO", "master"),
471-
)
467+
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "master"))
468+
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"})
472469

473470
http.Register(
474471
httpmock.GraphQL(`mutation PullRequestMerge\b`),
@@ -505,11 +502,8 @@ func Test_divergingPullRequestWarning(t *testing.T) {
505502
}
506503
stubCommit(pr, "COMMITSHA1")
507504

508-
shared.RunCommandFinder(
509-
"",
510-
pr,
511-
baseRepo("OWNER", "REPO", "master"),
512-
)
505+
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "master"))
506+
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"})
513507

514508
http.Register(
515509
httpmock.GraphQL(`mutation PullRequestMerge\b`),

pkg/cmd/pr/status/fixtures/prStatusCurrentBranchClosed.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@
1212
"state": "CLOSED",
1313
"url": "https://github.com/cli/cli/pull/8",
1414
"headRefName": "blueberries",
15-
"reviewDecision": "CHANGES_REQUESTED",
16-
"commits": {
17-
"nodes": [
18-
{
19-
"commit": {
20-
"statusCheckRollup": {
21-
"contexts": {
22-
"nodes": [
23-
{
24-
"state": "SUCCESS"
25-
}
26-
]
27-
}
28-
}
29-
}
30-
}
31-
]
32-
}
15+
"reviewDecision": "CHANGES_REQUESTED"
3316
}
3417
}
3518
]

pkg/cmd/pr/status/fixtures/prStatusCurrentBranchMerged.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@
1212
"state": "MERGED",
1313
"url": "https://github.com/cli/cli/pull/8",
1414
"headRefName": "blueberries",
15-
"reviewDecision": "CHANGES_REQUESTED",
16-
"commits": {
17-
"nodes": [
18-
{
19-
"commit": {
20-
"statusCheckRollup": {
21-
"contexts": {
22-
"nodes": [
23-
{
24-
"state": "SUCCESS"
25-
}
26-
]
27-
}
28-
}
29-
}
30-
}
31-
]
32-
}
15+
"reviewDecision": "CHANGES_REQUESTED"
3316
}
3417
}
3518
]

0 commit comments

Comments
 (0)