Merge pull request #3462 from swordqiu/hotfix/qj-approve-scripts-imporvements

fix: approve scripts imporvements, alllow approve_all PRs
This commit is contained in:
yunion-ci-robot
2019-11-04 22:47:15 +08:00
committed by GitHub
2 changed files with 66 additions and 7 deletions
+21 -7
View File
@@ -10,7 +10,21 @@ fi
function mergeable() {
local PRN=$1
hub api repos/{owner}/{repo}/pulls/$PRN | python -m json.tool | grep '"mergeable": true'
while true; do
local STATE=$(hub api repos/{owner}/{repo}/pulls/$PRN | python -m json.tool | grep '"mergeable":' | cut -d ":" -f 2 | cut -d "," -f 1)
STATE=$(eval "echo $STATE")
echo "merge state is $STATE"
case "$STATE" in
true)
return 0
;;
null)
;;
*)
return 1
;;
esac
done
}
function pr_state() {
@@ -59,14 +73,14 @@ function label() {
return 1
}
if ! mergeable $PR > /dev/null; then
echo "Pull request $PR is not mergeable (DIRTY), exit..."
exit 1
fi
STATE=$(pr_state $PR)
if [ "$STATE" != "open" ]; then
echo "Pull request $PR state != open, exit..."
echo "Pull request $PR state $STATE != open, exit..."
exit 0
fi
if ! mergeable $PR; then
echo "Pull request $PR is not mergeable (DIRTY), exit..."
exit 1
fi
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
pushd $(dirname "$BASH_SOURCE") > /dev/null
CUR_DIR=$(pwd)
popd > /dev/null
PRN=$1
if [ -z "$PRN" ]; then
echo "$0 <PRN>"
exit 1
fi
pulldata=$(mktemp)
function cleanup {
rm -rf "$pulldata"
}
trap cleanup EXIT
hub api repos/{owner}/{repo}/pulls > $pulldata
PR_NUMBERS=()
for l in $(python -m json.tool $pulldata | grep "\"number\":" | cut -d ':' -f 2 | cut -d "," -f 1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
do
PR_NUMBERS+=("$l")
done
PRNS=("$PRN")
for INDEX in $(python -m json.tool $pulldata | grep "\"title\":" | cut -d '"' -f 4 | grep -nr "Automated cherry pick of #${PRN}:" | awk 'BEGIN{FS=":"}{print $2}')
do
INDEX=$((INDEX-1))
PRNS+=("${PR_NUMBERS[$INDEX]}")
done
echo "Going to merge the following pull requests ${PRNS[@]}:"
for PRN in "${PRNS[@]}"
do
$CUR_DIR/approve.sh $PRN
if [ "$?" -ne "0" ]; then
echo "Merge failed, exit."
exit 1
fi
done