From f9572810081711243e1b785c78608a4e330535f3 Mon Sep 17 00:00:00 2001 From: s3krit Date: Wed, 15 Jul 2020 13:30:18 +0200 Subject: [PATCH] [CI] Fix check_polkadot_companion_status.sh (#6631) * check changes_requested and approved separately * handle checking more than 1 CHANGES_REQUESTED review --- .../gitlab/check_polkadot_companion_status.sh | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/substrate/.maintain/gitlab/check_polkadot_companion_status.sh b/substrate/.maintain/gitlab/check_polkadot_companion_status.sh index b781831055..3a03d79081 100755 --- a/substrate/.maintain/gitlab/check_polkadot_companion_status.sh +++ b/substrate/.maintain/gitlab/check_polkadot_companion_status.sh @@ -1,13 +1,13 @@ #!/bin/sh # -# check for a polkadot companion pr and ensure it has approvals and is +# check for a polkadot companion pr and ensure it has approvals and is # mergeable # github_api_substrate_pull_url="https://api.github.com/repos/paritytech/substrate/pulls" github_api_polkadot_pull_url="https://api.github.com/repos/paritytech/polkadot/pulls" # use github api v3 in order to access the data without authentication -github_header="Authorization: token ${GITHUB_PR_TOKEN}" +github_header="Authorization: token ${GITHUB_PR_TOKEN}" boldprint () { printf "|\n| \033[1m${@}\033[0m\n|\n" ; } boldcat () { printf "|\n"; while read l; do printf "| \033[1m${l}\033[0m\n"; done; printf "|\n" ; } @@ -24,7 +24,7 @@ this job checks if there is a string in the description of the pr like polkadot companion: paritytech/polkadot#567 -or any other polkadot pr is mentioned in this pr's description and checks its +or any other polkadot pr is mentioned in this pr's description and checks its status. @@ -68,7 +68,10 @@ boldprint "companion pr: #${pr_companion}" # mergable and approved curl -H "${github_header}" -sS -o companion_pr.json \ - ${github_api_polkadot_pull_url}/${pr_companion} + ${github_api_polkadot_pull_url}/${pr_companion} + +pr_head_sha=$(jq -r -e '.head.sha' < companion_pr.json) +boldprint "Polkadot PR's HEAD SHA: $pr_head_sha" if jq -e .merged < companion_pr.json >/dev/null then @@ -85,11 +88,18 @@ else fi curl -H "${github_header}" -sS -o companion_pr_reviews.json \ - ${github_api_polkadot_pull_url}/${pr_companion}/reviews + ${github_api_polkadot_pull_url}/${pr_companion}/reviews -if [ -n "$(jq -r -e '.[].state | select(. == "CHANGES_REQUESTED")' < companion_pr_reviews.json)" ] && \ - [ -z "$(jq -r -e '.[].state | select(. == "APPROVED")' < companion_pr_reviews.json)" ] -then +# If there are any 'CHANGES_REQUESTED' reviews for the *current* review +while IFS= read -r line; do + if [ "$line" = "$pr_head_sha" ]; then + boldprint "polkadot pr #${pr_companion} has CHANGES_REQUESTED for the latest commit" + exit 1 + fi +done <<< $(jq -r -e '.[] | select(.state == "CHANGES_REQUESTED").commit_id' < companion_pr_reviews.json) + +# Then we check for at least 1 APPROVED +if [ -z "$(jq -r -e '.[].state | select(. == "APPROVED")' < companion_pr_reviews.json)" ]; then boldprint "polkadot pr #${pr_companion} not APPROVED" exit 1 fi