How do I enable auto-merge on a github pull request via the Rest API

Viewed 522

I have permission, the repo allows it. I create a bunch of PRs using a cli tool and then I have to go open N tabs and double click the Enable Auto-Merge -> Confirm process for each one.

Does the API offer an issue/pr modify method to set this attribute automatically without resorting to the UI?

2 Answers

It seems that at the moment it's not possible to do it via Rest API, but you can use GraphQL API mutation enablePullRequestAutoMerge instead.

I solved it like this: Request POST to https://api.github.com/graphql to get pullRequestID value body:

query MyQuery {
    repository(name: "repo-example", owner: "org-example) {
        pullRequest(number: 49) {
                  id
              }
        } 
}

With pullRequest ID make a mutation: Request POST to https://api.github.com/graphql

mutation MyMutation {
    enablePullRequestAutoMerge(input: {pullRequestId: "$pullRequestID", mergeMethod: MERGE}) {
        clientMutationId
         }
}
Related