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

There are now several actions in the Github Marketplace that will check for PRs with conflicts and add a label to them, allowing the list to easily be filtered by that label. I think that’s the route I’m going to take.

(Though it sure would be nice if Github’s PR list automatically displayed an icon for conflicting PRs. The same way it does for PRs with linked issues, and for issues with linked PRs.)

Took a little auditioning and experimentation, but I now have a Github Actions workflow for eps1lon/actions-label-merge-conflict installed in both of our project repos that receive regular PR contributions.

So far it seems to be working out well, every time there’s a push to our default branch, it scans all of the open PRs for detected conflicts, adds a label of my choosing, and leaves a comment on the PR (to generate an email notification to the submitter).

If you do decide to try it out, though, be sure you write your workflow so that it

uses: eps1lon/actions-label-merge-conflict@v2.0.1

instead of the version 2.0.0 that’s listed as the latest release at the project page. 2.0.0 has a bit of a retry-timeout-cascade problem thing that predictably hit us on our very first outing with it, so that I had to stop the workflow after a solid 30 minutes of spinning its wheels fruitlessly. 2.0.1 generally completes in under 5-10 minutes.

(There’s some expected lag to the whole process, because Github’s conflict-detection jobs are processed asynchronously… so any tool that acts on them has to be prepared to wait for those results to show up, after there’s activity on the branch.)