How to get the default merge method for a pull request from github graphql query?

Viewed 144

Using a Github graphql query below I can see which merge options a repository has available:

{
  node(id: "<id>") {
    ... on PullRequest {
      number
      repository {
        mergeCommitAllowed
        squashMergeAllowed
        rebaseMergeAllowed
      }
    }
  }
}

that returns:

{
  "data": {
    "node": {
      "number": 666,
      "repository": {
        "mergeCommitAllowed": false,
        "squashMergeAllowed": true,
        "rebaseMergeAllowed": true
      }
    }
  }
}

But, I don't see a way to know which is the default. When I look at the pull request on Github (see below), it knows that rebase is the preferred method for merging my pull request. Perhaps there is some kind of "sticky" data attached to my user? (I'm sure the last pull request I closed was using rebase)

Is it possible to know which merge method is the default with a graphql query?

enter image description here enter image description here enter image description here

2 Answers

Here's an example query which returns the default merge method for the authenticated user. replace owner and name as appropriate.

{
  repository(owner: "TeamCodeStream", name: "codestream") {
    viewerDefaultMergeMethod
  }
}

I believe this is sticky to your user and possibly the repository. I've used a non-default merge method on a repository in the past, and when I came back, the merge button suggested the same value, which was definitely not the value I typically used.

The API wouldn't show you this, since that information is not a property of the repository, but both the repository and the user. API responses are not supposed to change based on the person who makes them unless there's an access control issue. Anyway, when performing a merge through the GraphQL API, the API defaults to the merge method anyway unless you specify something different.

Related