Skip to content

Instantly share code, notes, and snippets.

@jnothman
Created June 21, 2018 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnothman/41a5e05c82c4508afa7bee3b493752dd to your computer and use it in GitHub Desktop.
Save jnothman/41a5e05c82c4508afa7bee3b493752dd to your computer and use it in GitHub Desktop.
Identify which lines in master are modified by open pull requests
#!/bin/bash
# requires curl, jq, python
# set these variables
repo=scikit-learn/scikit-learn
remote=upstream
token= # GitHub personal access token goes here
list_open_prs() {
npages=$(curl -I "https://api.github.com/repos/$repo/pulls?state=open&per_page=100&access_token=$token&page=1" | grep ^Link: | grep -o 'page=[0-9]*>; rel="last"' | grep -o '[0-9][0-9]*')
for i in $(seq 1 $npages)
do
curl "https://api.github.com/repos/$repo/pulls?state=open&per_page=100&access_token=$token&page=$i" | jq '.[] | .number'
done
}
open_prs=$(list_open_prs)
git fetch $remote $(echo $open_prs | sed "s|[0-9][0-9]*|refs/pull/&/head:refs/remotes/$remote/pr/&|g")
rm lines-modified-merge{fail,success}
for pr in $open_prs
do
git checkout -f --detach HEAD
git reset --hard $remote/pr/$pr --
mergestatus=success
git merge --quiet --no-edit master >/dev/null || mergestatus=fail
git diff -U1 master | grep -e '^---' -e '^@@' | sed 's/ +[0-9].*//' | python -c '
import sys
for l in sys.stdin:
if l.startswith("---"):
path = l.partition("/")[-1].rstrip()
else:
start = l.partition("-")[-1]
start, n = start.split(",") if "," in start else (start, "2")
for i in range(int(start), int(start) + int(n)):
print(sys.argv[1], path, i, sep="\t")
' $pr >> lines-modified-merge$mergestatus.txt || break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment