Listing mergeable PRs on the repositories

Hi,

As discussed on today's call, I took a look at retrieving all approved and mergeable PRs on the repositories. This requires quite the incantation, but it's doable.

Using the Github CLI (gh):

gh pr list --state open \
                            --json number,title,reviewDecision,statusCheckRollup,mergeable \
                            --jq '
                          .[]
                          | select(.reviewDecision == "APPROVED")
                          | select(.mergeable == "MERGEABLE")
                          | select(
                              all(
                                .statusCheckRollup[]?;
                                if .__typename == "CheckRun" then
                                  .conclusion == "SUCCESS"
                                elif .__typename == "StatusContext" then
                                  .state == "SUCCESS"
                                else
                                  false
                                end
                              )
                            )
                          | [.number, .title]
                          | @tsv
                      '

You can pass a different repository with -R. If you do this in a repo checkout it'll pick it up from the Git config. CheckRun are the Github Action runs, StatusContext is the repository manager check. 

If you prefer curl, you'll need the GraphQL API and reshape the initial data to then tack on the same jq filter. The Github CLI does the initial reshaping of the data itself, so we have to replicate that. There is possibly an easier way, but this is what I managed to put together looking at its debug output:

curl -fsS \
  -H 'Accept: application/vnd.github+json' \
  -H "Authorization: Bearer GITHUB_API_TOKEN" \
  -H 'X-GitHub-Api-Version: 2026-03-10' \
  -H 'Content-Type: application/json' \
  'https://api.github.com/graphql' \
  --data "$(jq -n \
    --arg query '
      query($owner: String!, $repo: String!) {
        repository(owner: $owner, name: $repo) {
          pullRequests(states: OPEN, first: 100) {
            nodes {
              number
              title
              reviewDecision
              mergeable
              commits(last: 1) {
                nodes {
                  commit {
                    statusCheckRollup {
                      contexts(first: 100) {
                        nodes {
                          __typename
                          ... on CheckRun {
                            conclusion
                          }
                          ... on StatusContext {
                            state
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    ' \
    --arg owner 'w3c' \
    --arg repo 'json-ld-api' \
    '{query: $query, variables: {owner: $owner, repo: $repo}}')" |
jq '
  [
    .data.repository.pullRequests.nodes[]
    | {
        number,
        title,
        reviewDecision,
        mergeable,
        statusCheckRollup:
          (.commits.nodes[0].commit.statusCheckRollup.contexts.nodes // [])
      }
  ]
' |
jq -r '
  .[]
  | select(.reviewDecision == "APPROVED")
  | select(.mergeable == "MERGEABLE")
  | select(
      all(
        .statusCheckRollup[]?;
        if .__typename == "CheckRun" then
          .conclusion == "SUCCESS"
        elif .__typename == "StatusContext" then
          .state == "SUCCESS"
        else
          false
        end
      )
    )
  | [.number, .title]
  | @tsv
'

For json-ld-apl, that returns the following PRs:
* 709 Add PHP-JSON-LD implementation report
* 707 compaction: empty array and candidate selection
* 706 expansion: add test for default language
* 705 expand: certain keywords are dropped
* 686 tests: add expand #t0132 (@base vs property keys)

Kind regards,

-- 
Daenney

Received on Wednesday, 16 September 2026 22:02:33 UTC