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

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?



Solution 1:[1]

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
         }
}

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan Bezerra de Oliveira
Solution 2 polart