Fix pr merge on GHE < 3.0

This avoids loading authorship information for git commits, since it
relies on a GraphQL API that wasn't available before GHE v3.0. The
authorship information wasn't necessary for the merge operation anyway;
just loading the last commit OID was.
This commit is contained in:
Mislav Marohnić 2021-05-21 17:35:41 +02:00
parent ca04e21921
commit 6bec7a956a
3 changed files with 7 additions and 11 deletions

View file

@ -208,6 +208,8 @@ func PullRequestGraphQL(fields []string) string {
q = append(q, prFiles)
case "commits":
q = append(q, prCommits)
case "lastCommit": // pseudo-field
q = append(q, `commits(last:1){nodes{commit{oid}}}`)
case "commitsCount": // pseudo-field
q = append(q, `commits{totalCount}`)
case "statusCheckRollup":

View file

@ -156,7 +156,7 @@ func mergeRun(opts *MergeOptions) error {
findOptions := shared.FindOptions{
Selector: opts.SelectorArg,
Fields: []string{"id", "number", "state", "title", "commits", "mergeable", "headRepositoryOwner", "headRefName"},
Fields: []string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"},
}
pr, baseRepo, err := opts.Finder.Find(findOptions)
if err != nil {

View file

@ -464,11 +464,8 @@ func Test_nonDivergingPullRequest(t *testing.T) {
}
stubCommit(pr, "COMMITSHA1")
shared.RunCommandFinder(
"",
pr,
baseRepo("OWNER", "REPO", "master"),
)
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "master"))
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"})
http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`),
@ -505,11 +502,8 @@ func Test_divergingPullRequestWarning(t *testing.T) {
}
stubCommit(pr, "COMMITSHA1")
shared.RunCommandFinder(
"",
pr,
baseRepo("OWNER", "REPO", "master"),
)
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "master"))
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCommit", "mergeable", "headRepositoryOwner", "headRefName"})
http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`),