From 1eb6e5ef7307e6e9044a02a945e3f93e263ab060 Mon Sep 17 00:00:00 2001 From: Ryder Date: Fri, 7 May 2021 19:02:08 +0800 Subject: [PATCH] Retry if the PR is unrebaseable (#75) * Retry if the PR is unrebaseable * Remove useless code --- entrypoint.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 57cdbc8..204467e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,8 +21,27 @@ URI=https://api.github.com API_HEADER="Accept: application/vnd.github.v3+json" AUTH_HEADER="Authorization: token $GITHUB_TOKEN" -pr_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \ - "${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER") +MAX_RETRIES=${MAX_RETRIES:-6} +RETRY_INTERVAL=${RETRY_INTERVAL:-10} +REBASEABLE="" +pr_resp="" +for ((i = 0 ; i < $MAX_RETRIES ; i++)); do + pr_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \ + "${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER") + REBASEABLE=$(echo "$pr_resp" | jq -r .rebaseable) + if [[ "$REBASEABLE" == "null" ]]; then + echo "The PR is not ready to rebase, retry after $RETRY_INTERVAL seconds" + sleep $RETRY_INTERVAL + continue + else + break + fi +done + +if [[ "$REBASEABLE" != "true" ]] ; then + echo "GitHub doesn't think that the PR is rebaseable!" + exit 1 +fi BASE_REPO=$(echo "$pr_resp" | jq -r .base.repo.full_name) BASE_BRANCH=$(echo "$pr_resp" | jq -r .base.ref) @@ -30,7 +49,7 @@ BASE_BRANCH=$(echo "$pr_resp" | jq -r .base.ref) USER_LOGIN=$(jq -r ".comment.user.login" "$GITHUB_EVENT_PATH") user_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \ - "${URI}/users/${USER_LOGIN}") + "${URI}/users/${USER_LOGIN}") USER_NAME=$(echo "$user_resp" | jq -r ".name") if [[ "$USER_NAME" == "null" ]]; then @@ -43,12 +62,6 @@ if [[ "$USER_EMAIL" == "null" ]]; then USER_EMAIL="$USER_LOGIN@users.noreply.github.com" fi -if [[ "$(echo "$pr_resp" | jq -r .rebaseable)" != "true" ]]; then - echo "GitHub doesn't think that the PR is rebaseable!" - echo "API response: $pr_resp" - exit 1 -fi - if [[ -z "$BASE_BRANCH" ]]; then echo "Cannot get base branch information for PR #$PR_NUMBER!" exit 1