Skip to content

Commit

Permalink
Retry if the PR is unrebaseable (cirrus-actions#75)
Browse files Browse the repository at this point in the history
* Retry if the PR is unrebaseable

* Remove useless code
  • Loading branch information
ddzero2c authored and cjw6k committed Apr 26, 2022
1 parent 2e45b21 commit 736d6b3
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions entrypoint.sh
100755 → 100644
Expand Up @@ -21,47 +21,40 @@ URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"

n=0
until [ "$n" -ge 5 ]
do
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" == "true" ]]; then
"${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
elif [[ "$rebaseable" == "false" ]]; then
curl -X POST -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
"${URI}/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
-d "{\"body\": \"GitHub doesn't think that the PR is rebaseable!\"}"

echo "GitHub doesn't think that the PR is rebaseable!"
echo "API response: $pr_resp"
exit 1
fi

n=$((n+1))
sleep 15
done

if [ "$n" -ge 5 ]
if [[ "$REBASEABLE" != "true" ]] ; then
curl -X POST -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
"${URI}/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
-d "{\"body\": \"Failed to rebase after 5 attempts.\"}"

echo "Failed to rebase after 5 attempts."
echo "API response: $pr_resp"
exit 1
done
fi

BASE_REPO=$(echo "$pr_resp" | jq -r .base.repo.full_name)
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
Expand Down

0 comments on commit 736d6b3

Please sign in to comment.