Is there an API to filter out list of PRs from a folder within a mono repository in GitHub?

17 Views Asked by At

I have a main repository “mainrepo” and it has multiple folders (one of them is “subfolder3” but I need a list of PRs within a folder inside the main repository.

I tried using GET /repos/{owner}/{repo}/pulls?state=closed&base=subfoldername

1

There are 1 best solutions below

0
Benjamin W. On

You can use the GitHub CLI to get a list of all closed PR, list them with URL, title, and list of modified files, and then use a jq query to filter for only those that touch the relevant directory:

gh pr list --state closed --json title,files,url --jq '
    map(
      select(
        .files
        | any(.path | startswith("subfolder3/"))
      )
      | {title, url}
    )
'

This return an array of objects, like this:

[
  {
    "title": "Title of the first matching PR",
    "url": "https://github.com/ORG/REPO/pull/123"
  },
  {
    "title": "Title of the second matching PR",
    "url": "https://github.com/ORG/REPO/pull/234"
  },
  // etc.
]