[improve][CI] Don't run CI when PR is in draft status or isn't mergeable
@@ -160,15 +160,15 @@ function ci_check_ready_to_test() {
return 1
fi
- PR_JSON=$(jq '.pull_request' "${GITHUB_EVENT_PATH}")
-
- # when re-running, the event doesn't get updated, fetch the PR JSON
- if [[ $GITHUB_RUN_ATTEMPT -gt 1 ]]; then
PR_JSON_URL=$(jq -r '.pull_request.url' "${GITHUB_EVENT_PATH}")
echo "Refreshing $PR_JSON_URL..."
PR_JSON=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "${PR_JSON_URL}")
- fi
+ if printf "%s" "${PR_JSON}" | jq -e '.draft | select(. == true)' &> /dev/null; then
+ echo "PR is draft."
+ elif ! ( printf "%s" "${PR_JSON}" | jq -e '.mergeable | select(. == true)' &> /dev/null ); then
+ echo "PR isn't mergeable."
+ else
# check ready-to-test label
if printf "%s" "${PR_JSON}" | jq -e '.labels[] | .name | select(. == "ready-to-test")' &> /dev/null; then
echo "Found ready-to-test label."
@@ -188,6 +188,7 @@ function ci_check_ready_to_test() {
if [[ "$PR_REVIEW_DECISION" == "APPROVED" ]]; then
return 0
fi
+ fi
FORK_REPO_URL=$(jq -r '.pull_request.head.repo.html_url' "$GITHUB_EVENT_PATH")
PR_BRANCH_LABEL=$(jq -r '.pull_request.head.label' "$GITHUB_EVENT_PATH")
