forked from OpenXT/openxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[github] add titles to list_open_pull_requests.sh, and new script for…
… getting the pull request of a given commit
- Loading branch information
Jean-Edouard Lejosne
committed
Mar 30, 2015
1 parent
ac5a16d
commit 5a5a98b
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters