Get help from @Philippe and @knight9631, I got the expect result.
Prerequisite
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
Get the related PRs which are still not merged.
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
Demo
$ bash PR.sh abc.json
PR 22857 hasn't been merged
PR 19231 hasn't been merged
PR 22981 hasn't been merged
Notes:
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)