Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: merge-pr now checks that PR status is green before proceeding #21810

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions scripts/github/merge-pr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BASEDIR=`(cd $BASEDIR; pwd)`

PR_NUMBER=0
PUSH_UPSTREAM=1
FORCE=0
while [[ $# -gt 0 ]]
do
key="$1"
Expand All @@ -16,6 +17,10 @@ do
PUSH_UPSTREAM=0
shift # past argument
;;
--force)
FORCE=1
shift # past argument
;;
*) # unknown option
PR_NUMBER="$1" # save it in an array for later
shift # past argument
Expand All @@ -24,22 +29,26 @@ do
done

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 "$0 PR_NUMBER [--dryrun]"
echo "$0 PR_NUMBER [--dryrun] [--force]"
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
fi

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"""`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to talk to @alexeagle about his nifty json parsing libary he showed me the other day.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, he showed me as well. Will see if we can convert it.

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_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_CLA=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^cla"`
MASTER_BRANCH='master'
SHA=`git rev-parse HEAD`
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`
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`

if [[ "$PR_ACTION" != "PR action: merge" ]]; then
echo The PR is missing 'PR action: merge' label, found: $PR_ACTION
Expand All @@ -51,6 +60,15 @@ if [[ "$PR_CLA" != "cla: yes" ]]; then
exit 1
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
MERGE_MASTER=1
Expand Down