From 6adf24ca0c70a5fd235ce3f1199f6c76830f9488 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com>
Date: Fri, 26 Mar 2021 14:21:00 +0100
Subject: [PATCH] Change companion check order (#8460)

* Change companion check order

Apparently if the pr isn't approved it counts as not mergable. However,
this is rahter confusing. To fix this, we just change the order.

* Move exit
---
 .../gitlab/check_polkadot_companion_status.sh | 43 +++++++++----------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/substrate/.maintain/gitlab/check_polkadot_companion_status.sh b/substrate/.maintain/gitlab/check_polkadot_companion_status.sh
index 4714baf54fb..bfd27e6347c 100755
--- a/substrate/.maintain/gitlab/check_polkadot_companion_status.sh
+++ b/substrate/.maintain/gitlab/check_polkadot_companion_status.sh
@@ -56,27 +56,7 @@ fi
 boldprint "companion pr: #${pr_companion}"
 
 # check the status of that pull request - needs to be
-# mergable and approved
-
-curl -H "${github_header}" -sS -o companion_pr.json \
-  ${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
-  boldprint "polkadot pr #${pr_companion} already merged"
-  exit 0
-fi
-
-if jq -e '.mergeable' < companion_pr.json >/dev/null
-then
-  boldprint "polkadot pr #${pr_companion} mergeable"
-else
-  boldprint "polkadot pr #${pr_companion} not mergeable"
-  exit 1
-fi
+# approved and mergable
 
 curl -H "${github_header}" -sS -o companion_pr_reviews.json \
   ${github_api_polkadot_pull_url}/${pr_companion}/reviews
@@ -98,6 +78,25 @@ if [ -z "$(jq -r -e '.[].state | select(. == "APPROVED")' < companion_pr_reviews
 fi
 
 boldprint "polkadot pr #${pr_companion} state APPROVED"
-exit 0
 
+curl -H "${github_header}" -sS -o companion_pr.json \
+  ${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
+  boldprint "polkadot pr #${pr_companion} already merged"
+  exit 0
+fi
+
+if jq -e '.mergeable' < companion_pr.json >/dev/null
+then
+  boldprint "polkadot pr #${pr_companion} mergeable"
+else
+  boldprint "polkadot pr #${pr_companion} not mergeable"
+  exit 1
+fi
 
+exit 0
-- 
GitLab