build: merge-pr now checks that PR status is green before proceeding (#21810)
Optionally one can use `--force` to override and merge no non-green PR. PR Close #21810
This commit is contained in:
parent
8df56fe93a
commit
e0b31dbfef
|
@ -7,6 +7,7 @@ BASEDIR=`(cd $BASEDIR; pwd)`
|
||||||
|
|
||||||
PR_NUMBER=0
|
PR_NUMBER=0
|
||||||
PUSH_UPSTREAM=1
|
PUSH_UPSTREAM=1
|
||||||
|
FORCE=0
|
||||||
while [[ $# -gt 0 ]]
|
while [[ $# -gt 0 ]]
|
||||||
do
|
do
|
||||||
key="$1"
|
key="$1"
|
||||||
|
@ -16,6 +17,10 @@ do
|
||||||
PUSH_UPSTREAM=0
|
PUSH_UPSTREAM=0
|
||||||
shift # past argument
|
shift # past argument
|
||||||
;;
|
;;
|
||||||
|
--force)
|
||||||
|
FORCE=1
|
||||||
|
shift # past argument
|
||||||
|
;;
|
||||||
*) # unknown option
|
*) # unknown option
|
||||||
PR_NUMBER="$1" # save it in an array for later
|
PR_NUMBER="$1" # save it in an array for later
|
||||||
shift # past argument
|
shift # past argument
|
||||||
|
@ -24,22 +29,26 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$PR_NUMBER" -eq 0 ]; then
|
if [ "$PR_NUMBER" -eq 0 ]; then
|
||||||
echo "Merge github PR into the target branches"
|
echo "Merge github PR into the target branches if status is green"
|
||||||
echo
|
echo
|
||||||
echo "$0 PR_NUMBER [--dryrun]"
|
echo "$0 PR_NUMBER [--dryrun] [--force]"
|
||||||
echo
|
echo
|
||||||
|
echo --dryrun Performs all operations but does not push the merge back to git@github.com:angular/angular.git.
|
||||||
|
echo --force Continues even if PR status is not green.
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
PR_SHA_COUNT=`curl -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER | node $BASEDIR/utils/json_extract.js commits`
|
PULL_JSON=`curl -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER`
|
||||||
|
PR_SHA_COUNT=`node $BASEDIR/utils/json_extract.js commits <<< """$PULL_JSON"""`
|
||||||
|
STATUS_JSON_URL=`node $BASEDIR/utils/json_extract.js _links.statuses.href <<< """$PULL_JSON"""`
|
||||||
|
STATUS=`curl -s $STATUS_JSON_URL | node $BASEDIR/utils/json_extract.js description | cut -d '|' -f1`
|
||||||
PR_LABELS=`curl -s https://api.github.com/repos/angular/angular/issues/$PR_NUMBER/labels`
|
PR_LABELS=`curl -s https://api.github.com/repos/angular/angular/issues/$PR_NUMBER/labels`
|
||||||
PR_ACTION=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^PR action:"`
|
PR_ACTION=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^PR action:"`
|
||||||
PR_TARGET=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^PR target:"`
|
PR_TARGET=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^PR target:"`
|
||||||
PR_CLA=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^cla"`
|
PR_CLA=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^cla"`
|
||||||
MASTER_BRANCH='master'
|
MASTER_BRANCH='master'
|
||||||
SHA=`git rev-parse HEAD`
|
PATCH_BRANCH=`git ls-remote --heads git@github.com:angular/angular.git | grep -E 'refs\/heads\/[0-9]+\.[0-9]+\.x' | cut -d '/' -f3 | sort -r | head -n1`
|
||||||
PATCH_BRANCH=`git ls-remote --heads git@github.com:angular/angular.git | grep -E 'refs\/heads\/\d+\.\d+\.x' | cut -d '/' -f3 | sort -r | head -n1`
|
|
||||||
|
|
||||||
if [[ "$PR_ACTION" != "PR action: merge" ]]; then
|
if [[ "$PR_ACTION" != "PR action: merge" ]]; then
|
||||||
echo The PR is missing 'PR action: merge' label, found: $PR_ACTION
|
echo The PR is missing 'PR action: merge' label, found: $PR_ACTION
|
||||||
|
@ -51,6 +60,15 @@ if [[ "$PR_CLA" != "cla: yes" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$STATUS" != "All checks passed!" ]]; then
|
||||||
|
echo PR $PR_NUMBER is failing with: $STATUS
|
||||||
|
if [[ $FORCE == 1 ]]; then
|
||||||
|
echo FORCING: --force flag used to ignor PR status.
|
||||||
|
else
|
||||||
|
echo Exting...
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $PR_TARGET == "PR target: master & patch" ]]; then
|
if [[ $PR_TARGET == "PR target: master & patch" ]]; then
|
||||||
MERGE_MASTER=1
|
MERGE_MASTER=1
|
||||||
|
|
Loading…
Reference in New Issue