Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 4082d75

Browse files
authored
[CI] Fix check_polkadot_companion_status.sh (#6631)
* check changes_requested and approved separately * handle checking more than 1 CHANGES_REQUESTED review
1 parent f4031f6 commit 4082d75

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

.maintain/gitlab/check_polkadot_companion_status.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/sh
22
#
3-
# check for a polkadot companion pr and ensure it has approvals and is
3+
# check for a polkadot companion pr and ensure it has approvals and is
44
# mergeable
55
#
66

77
github_api_substrate_pull_url="https://api.github.com/repos/paritytech/substrate/pulls"
88
github_api_polkadot_pull_url="https://api.github.com/repos/paritytech/polkadot/pulls"
99
# use github api v3 in order to access the data without authentication
10-
github_header="Authorization: token ${GITHUB_PR_TOKEN}"
10+
github_header="Authorization: token ${GITHUB_PR_TOKEN}"
1111

1212
boldprint () { printf "|\n| \033[1m${@}\033[0m\n|\n" ; }
1313
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
2424
2525
polkadot companion: paritytech/polkadot#567
2626
27-
or any other polkadot pr is mentioned in this pr's description and checks its
27+
or any other polkadot pr is mentioned in this pr's description and checks its
2828
status.
2929
3030
@@ -68,7 +68,10 @@ boldprint "companion pr: #${pr_companion}"
6868
# mergable and approved
6969

7070
curl -H "${github_header}" -sS -o companion_pr.json \
71-
${github_api_polkadot_pull_url}/${pr_companion}
71+
${github_api_polkadot_pull_url}/${pr_companion}
72+
73+
pr_head_sha=$(jq -r -e '.head.sha' < companion_pr.json)
74+
boldprint "Polkadot PR's HEAD SHA: $pr_head_sha"
7275

7376
if jq -e .merged < companion_pr.json >/dev/null
7477
then
@@ -85,11 +88,18 @@ else
8588
fi
8689

8790
curl -H "${github_header}" -sS -o companion_pr_reviews.json \
88-
${github_api_polkadot_pull_url}/${pr_companion}/reviews
89-
90-
if [ -n "$(jq -r -e '.[].state | select(. == "CHANGES_REQUESTED")' < companion_pr_reviews.json)" ] && \
91-
[ -z "$(jq -r -e '.[].state | select(. == "APPROVED")' < companion_pr_reviews.json)" ]
92-
then
91+
${github_api_polkadot_pull_url}/${pr_companion}/reviews
92+
93+
# If there are any 'CHANGES_REQUESTED' reviews for the *current* review
94+
while IFS= read -r line; do
95+
if [ "$line" = "$pr_head_sha" ]; then
96+
boldprint "polkadot pr #${pr_companion} has CHANGES_REQUESTED for the latest commit"
97+
exit 1
98+
fi
99+
done <<< $(jq -r -e '.[] | select(.state == "CHANGES_REQUESTED").commit_id' < companion_pr_reviews.json)
100+
101+
# Then we check for at least 1 APPROVED
102+
if [ -z "$(jq -r -e '.[].state | select(. == "APPROVED")' < companion_pr_reviews.json)" ]; then
93103
boldprint "polkadot pr #${pr_companion} not APPROVED"
94104
exit 1
95105
fi

0 commit comments

Comments
 (0)