1
1
#! /bin/sh
2
2
#
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
4
4
# mergeable
5
5
#
6
6
7
7
github_api_substrate_pull_url=" https://api.github.com/repos/paritytech/substrate/pulls"
8
8
github_api_polkadot_pull_url=" https://api.github.com/repos/paritytech/polkadot/pulls"
9
9
# 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} "
11
11
12
12
boldprint () { printf " |\n| \033[1m${@ } \033[0m\n|\n" ; }
13
13
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
24
24
25
25
polkadot companion: paritytech/polkadot#567
26
26
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
28
28
status.
29
29
30
30
@@ -68,7 +68,10 @@ boldprint "companion pr: #${pr_companion}"
68
68
# mergable and approved
69
69
70
70
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 "
72
75
73
76
if jq -e .merged < companion_pr.json > /dev/null
74
77
then
85
88
fi
86
89
87
90
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
93
103
boldprint " polkadot pr #${pr_companion} not APPROVED"
94
104
exit 1
95
105
fi
0 commit comments