Reputation: 45223
Work on a big open source repository in Github. There are more than 300 pull requests (PR) waiting the queue to be merged to master branch.
I'd like to add features in a file, before to do that, I need to make sure there are no exist PRs making the same change.
So how to find out the pull requests which include a change in a particular file?
Upvotes: 7
Views: 6456
Reputation: 45223
Get help from @Philippe and @knight9631, I got the expect result.
Do upstream
change as described in @Philippe's reply.
$ git remote add upstream https://github.com/[orga]/[project].git
# add fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to .git/config in session origin
$ git fetch --all
Run below script.
FILENAME=$1
git log --all --format=%d $FILENAME|awk -F "[\/|\)]" '/pr/{print $3}' |sort -n |while read line
do
state=$(curl -s https://api.github.com/repos/ansible/ansible/pulls/$line|jq -r .state)
if [[ $state == "open" ]]; then
echo "PR $line hasn't been merged"
fi
done
$ bash PR.sh abc.json
PR 22857 hasn't been merged
PR 19231 hasn't been merged
PR 22981 hasn't been merged
You need to add authorization token when getting Github API. Otherwise you will easily hit the rate-limiting
TOKEN="<your_own_token"
state=$(curl -s -H "Authorization: token $TOKEN" https://api.github.com/repos/ansible/ansible/pulls/$line|jq -r .state)
Upvotes: 1
Reputation: 31107
You could try to fetch all the PR branches in your local repository and then search for commits modifying the files.
Do achieve that, do:
Add the project repository as the upstream
remote.
git remote add upstream https://github.com/[orga]/[project].git
Open the .git\config
file and add the line fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
to the [upstream]
section. It should ends up looking like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/[orga]/[project].git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Do a git fetch --all
that will fetch all the remotes
Search for updates on the files you want:
List all commits (across all branches) for a given file
or even better for your need...
Find a Git branch containing changes to a given file
Upvotes: 1