Can I get a list of all pull requests related to a specific file/directory path in GitHub?
Asked Answered
R

4

12

Is it possible to get a list of pull requests that have touched any file under a given directory?

The other day, I had to wade through dozens of pull requests from the past several months and collect all the ones that had touched any file in under a particular path of interest.

I tried to search PRs using the file path on GitHub, but it didn't seem like file paths were indexed. Poking around a bit further, I couldn't really find a solution for file searching in pull requests, which was sort of surprising. I eventually had to go through the commit history of various directories and collect the related PRs, but it was fairly tedious.

Is there any support for summarizing PRs by affected files in GitHub? Perhaps this is something the API is capable of?

Remindful answered 27/2, 2017 at 22:28 Comment(1)
M
2
git log --merges --first-parent -- <file>

will show you commits that merged in changes to specific files. Since you use PR's to merge files chances are that this will be sufficient.

If this is not the case, however, and you have additional merge commits on the mainline that aren't PR's, you may need to use a combination of the --author=<pattern>, --committer=<pattern>, and --grep=<pattern> flags to further filter the output:

   --author=<pattern>, --committer=<pattern>
       Limit the commits output to ones with author/committer header lines that match
       the specified pattern (regular expression). With more than one
       --author=<pattern>, commits whose author matches any of the given patterns are
       chosen (similarly for multiple --committer=<pattern>).

   --grep=<pattern>
       Limit the commits output to ones with log message that matches the specified
       pattern (regular expression). With more than one --grep=<pattern>, commits whose
       message matches any of the given patterns are chosen (but see --all-match).

       When --show-notes is in effect, the message from the notes is matched as if it
       were part of the log message.
Malraux answered 28/2, 2017 at 1:38 Comment(2)
That's command-line git, not an ideal answer to a question that is (I believe) specific to the web interface to GitHub. Still, thank you.Retharethink
This at best only detects merged PRs, and excludes open or declined PRsSuberin
G
0

You can do this using the GitHub CLI, gh.

gh pr list can return a list of fields, including files. Combined with the built-in --jq argument you can use this to filter based on the files in the PR.

Here's an example that only returns all PRs from a particular repo that include a file that includes kafka in its name:

gh pr list --state all --repo rmoff/rmoff-blog \
           --json number,title,files           \
        --jq 'map(select(.files | any(.path | contains("kafka"))) | {number, title,files})'

However this returns all the files in the PR, so you might just want the PR number, title, and URL:

gh pr list --state all --repo rmoff/rmoff-blog \
           --json number,title,files,url           \
           --jq 'map(select(.files | any(.path | contains("kafka"))) | {number, title,url})'

[
  {
    "number": 76,
    "title": "NextDNS ngrok article",
    "url": "https://github.com/rmoff/rmoff-blog/pull/76"
  },
  {
    "number": 52,
    "title": "Kafka ngrok article",
    "url": "https://github.com/rmoff/rmoff-blog/pull/52"
  },
  {
    "number": 51,
    "title": "kafka -> apache kafka, remove tags in favour of categories",
    "url": "https://github.com/rmoff/rmoff-blog/pull/51"
  }
]
Garling answered 23/8, 2024 at 10:1 Comment(0)
N
-2

I just had the same question, you can just search for the path in the PR filter:

Github PR

Navar answered 17/7, 2023 at 11:15 Comment(3)
This does not actually work.Suberin
It does, see github.com/facebook/react/… - includes the PRs with path packages/react/client in itNavar
No, that's just returning PRs that contain a fuzzy string match to "packages/react/client" anywhere in a title, comment, or diff contents (but not affected file pathnames). Counter-example from that same repo: github.com/facebook/react/… with a longer pathname should return multiple PRs (eg #29957 github.com/facebook/react/pull/29957/files), but instead returns nothingSuberin
L
-3

Try

is:pr "your_filepath" in:path 

In the Filter textbox in the Pull Requests Tab of your repo

Lisandra answered 24/4, 2024 at 8:6 Comment(1)
This does not actually work.Suberin

© 2022 - 2025 — McMap. All rights reserved.