How do I search for PRs with conflicts?

I am trying to filter search results for PRs with conflicting files such that it says this in the PR:

There doesn’t seem to be any information on this in the documentation:

@aaronfranke - Great question! There’s not a specific qualifier in our search interface that would allow you to fetch a list of pull requests and filtering them for those with conflicting files.

One alternative approach that might be of interest is using our GraphQL API to fetch a list of pull requests and obtaining their number, URL and mergeable value. The mergeable field can be one of three values, where CONFLICTING would indicate that the pull request can’t be merged due to merge conflicts.

Here’s an example using the github/linguist repository:

query {
  repository(owner:"github", name:"linguist") {
    pullRequests(last: 10) {
      edges {
        node {
          number
          url 
          mergeable
        }
      }
    }
  }
}

Here’s the result set at this time of writing:

{
  "data": {
    "repository": {
      "pullRequests": {
        "edges": [
          {
            "node": {
              "number": 5029,
              "url": "https://github.com/github/linguist/pull/5029",
              "mergeable": "MERGEABLE"
            }
          },
          {
            "node": {
              "number": 5030,
              "url": "https://github.com/github/linguist/pull/5030",
              "mergeable": "MERGEABLE"
            }
          },
          {
            "node": {
              "number": 5034,
              "url": "https://github.com/github/linguist/pull/5034",
              "mergeable": "UNKNOWN"
            }
          },
          {
            "node": {
              "number": 5035,
              "url": "https://github.com/github/linguist/pull/5035",
              "mergeable": "MERGEABLE"
            }
          },
          {
            "node": {
              "number": 5036,
              "url": "https://github.com/github/linguist/pull/5036",
              "mergeable": "UNKNOWN"
            }
          },
          {
            "node": {
              "number": 5037,
              "url": "https://github.com/github/linguist/pull/5037",
              "mergeable": "UNKNOWN"
            }
          },
          {
            "node": {
              "number": 5040,
              "url": "https://github.com/github/linguist/pull/5040",
              "mergeable": "MERGEABLE"
            }
          },
          {
            "node": {
              "number": 5049,
              "url": "https://github.com/github/linguist/pull/5049",
              "mergeable": "UNKNOWN"
            }
          },
          {
            "node": {
              "number": 5050,
              "url": "https://github.com/github/linguist/pull/5050",
              "mergeable": "CONFLICTING"
            }
          },
          {
            "node": {
              "number": 5051,
              "url": "https://github.com/github/linguist/pull/5051",
              "mergeable": "CONFLICTING"
            }
          }
        ]
      }
    }
  }
}

You could adapt this approach for a different repository or a set of repositories scoped under an account or organization. I highly recommend checking out our documentation covering the GitHub GraphQL API, in addition to our guides if you haven’t already. I hope this helps!

1 Like