3

On Github I do a lot of work on a big repo with hundreds of pending PR's open.

When working on a file, it would be convenient to examine any pending changes on that file; this way I would avoid duplicating work fixing already fixed bugs, and keep an eye out for possible future conflicts.

Also, this search would be much more efficient than having to search the PR text by keywords... you know, having to guess how other people might have phrased things.

Is there a way to get Github to show me what I want? "Give me all PR's that contain proposed changes to file X"

If the feature doesn't exist, I'd love to know possible workarounds.. or how I can make the feature request to Github. Thanks

pgr
  • 1,042
  • 1
  • 9
  • 17

2 Answers2

4

This same question is treated in the Stack Overflow post
Is there a way to see what pending pull requests affect a particular file?

I reproduce below the answer by larsks for this question.


ElpieKay's answer is basically what I was suggesting in my comment; this answer has an example shell script that would largely automated the process.

It turns out that it is fairly easy to get a list of open pull requests; you can just the following curl command line to get a JSON list of open requests:

curl https://api.github.com/repos/<user>/<repo>/pulls

For example:

curl https://api.github.com/repos/centos-opstools/opstools-ansible/pulls

You can then extract the pull request numbers from that using something like jq (the -s argument to curl just suppresses some status output that you get when piping curl output to another command):

curl -s https://api.github.com/repos/centos-opstools/opstools-ansible/pulls |
jq '.[]|.number'

You could then take the output of that command and pipe it into a loop to fetch just those pull requests and inspect them for a file of interest:

curl -s https://api.github.com/repos/centos-opstools/opstools-ansible/pulls |
jq '.[]|.number' |
while read pr; do
  git fetch --quiet origin refs/pull/$pr/head
  if git show --pretty=format:'' --name-only FETCH_HEAD | grep -q $file_i_care_about; then
    echo "PR $pr"
  fi
done

Which would yield output like:

PR 82
PR 71
PR 69

The above assumes that the variable file_i_care_about is a variable containing the file in which you are interested.

harrymc
  • 480,290
  • Thanks. My only problem is that this is not from Github UI, and I need a way for less technical people to do it while triaging. They currently don't have working local git repos. What is the minimal git set up needed for this? git init followed by git remote? – pgr Aug 11 '22 at 14:09
  • I can't say - you'll have to try and see. – harrymc Aug 11 '22 at 14:38
  • This approach works but hits the pagination limits of the API. It only sends me batches of 30 PR's, with the per_page option I can increase that to 100, but I'd still have to deal with several API requests, and look at them one by one. Very inefficient for such a large repo with thousands of PRs like the one I work with most of the time. I opened a feature request for Github-cli regarding this: https://github.com/cli/cli/issues/6642 – pgr Nov 19 '22 at 16:26
  • 1
    Any way, I'd like to thank you for your answer and apologize for not looking at it properly back in August, I got derailed. Sorry – pgr Nov 19 '22 at 16:28
1

With Github CLI

gh pr list --json url,files | jq 'map(select(.files | map(.path | contains("lib/myfile.txt")) | any))'
skojin
  • 11
  • 3
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Sep 19 '23 at 12:28
  • Hey, thanks. That is interesting. It also seems to hit pagination problems... it's only really scanning the 30 first results, right? – pgr Sep 19 '23 at 16:19