diff --git a/github/commit_to_pull_request.sh b/github/commit_to_pull_request.sh new file mode 100755 index 000000000..86fda49cf --- /dev/null +++ b/github/commit_to_pull_request.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +[ $# -eq 3 ] || exit 1 + +# Generate a token there: https://github.com/settings/applications +TOKEN="$1" +REPO="$2" +COMMIT="$3" + +total=`curl -I -H "Authorization: token $TOKEN" -s "https://api.github.com/repos/openxt/${REPO}/pulls?state=closed" 2>&1 | grep ^Link | sed 's/.*page=\([0-9]\+\)>; rel="last".*/\1/'` +[ -z $total ] && total=1 + +page=1 +pull_requests="" +while [ $page -le $total ]; do + pull_requests="$pull_requests `curl -H "Authorization: token $TOKEN" -s "https://api.github.com/repos/openxt/${REPO}/pulls?state=closed&page=$page" | jq '.[].number'`" + page=$(( $page + 1 )) +done + +for pr in $pull_requests; do +# Filtering out rejected pull requests would make sense +# However it makes everything slower and uses twice as many requests +# Uncomment if needed +# merged=`curl -H "Authorization: token $TOKEN" -s "https://api.github.com/repos/openxt/${REPO}/pulls/${pr}" | jq '.merged'` +# [ "x$merged" != "xtrue" ] && continue + commits="`curl -H "Authorization: token $TOKEN" -s https://api.github.com/repos/openxt/${REPO}/pulls/${pr}/commits | jq '.[].sha'`" + if [ "$commits" != "" ]; then + for commit in $commits; do + sha=`echo $commit | cut -d '"' -f 2` + if [[ ${sha} == ${COMMIT}* ]]; then + echo "https://github.com/OpenXT/${REPO}/pull/${pr}" + exit 0 + fi + done + fi +done + +echo "Not found" +exit 1 diff --git a/github/list_open_pull_requests.sh b/github/list_open_pull_requests.sh index 032564cf8..3ec81f239 100755 --- a/github/list_open_pull_requests.sh +++ b/github/list_open_pull_requests.sh @@ -5,15 +5,25 @@ # Generate a token there: https://github.com/settings/applications TOKEN="$1" +# Get the list of OpenXT repos repos=`curl -H "Authorization: token $TOKEN" -s "https://api.github.com/users/openxt/repos?per_page=100" | jq '.[].name' | cut -d '"' -f 2` -for i in $repos; +for i in $repos; do - PRS="`curl -H "Authorization: token $TOKEN" -s https://api.github.com/repos/openxt/$i/pulls | jq '.[].number'`" + # Get the json list of pull requests + PULLS="`curl -H "Authorization: token $TOKEN" -s https://api.github.com/repos/openxt/$i/pulls`" + # Get the list of pull request numbers + PRS="`echo $PULLS | jq '.[].number'`" + # Get all the pull request titles, replacing ' ' with '/', + # to avoid messing with $IFS + TITLES=(`echo $PULLS | jq '.[].title' | sed 's| |/|g'`) if [ "$PRS" != "" ]; then echo "Repository: $i -- Open pull requests:" + n=0 for PR in $PRS; do - echo "https://github.com/OpenXT/$i/pull/$PR" + echo -n "https://github.com/OpenXT/$i/pull/$PR" + echo " - `echo ${TITLES[$n]} | sed 's|/| |g'`" + n=$(( $n + 1 )) done echo fi