Skip to content

Commit

Permalink
[github] add titles to list_open_pull_requests.sh, and new script for…
Browse files Browse the repository at this point in the history
… getting the pull request of a given commit
  • Loading branch information
Jean-Edouard Lejosne committed Mar 30, 2015
1 parent ac5a16d commit 5a5a98b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
39 changes: 39 additions & 0 deletions github/commit_to_pull_request.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions github/list_open_pull_requests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a5a98b

Please sign in to comment.