Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 1eb6e5e

Browse files
authored
Retry if the PR is unrebaseable (#75)
* Retry if the PR is unrebaseable * Remove useless code
1 parent b08442c commit 1eb6e5e

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

entrypoint.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,35 @@ URI=https://api.github.com
2121
API_HEADER="Accept: application/vnd.github.v3+json"
2222
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
2323

24-
pr_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
25-
"${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
24+
MAX_RETRIES=${MAX_RETRIES:-6}
25+
RETRY_INTERVAL=${RETRY_INTERVAL:-10}
26+
REBASEABLE=""
27+
pr_resp=""
28+
for ((i = 0 ; i < $MAX_RETRIES ; i++)); do
29+
pr_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
30+
"${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
31+
REBASEABLE=$(echo "$pr_resp" | jq -r .rebaseable)
32+
if [[ "$REBASEABLE" == "null" ]]; then
33+
echo "The PR is not ready to rebase, retry after $RETRY_INTERVAL seconds"
34+
sleep $RETRY_INTERVAL
35+
continue
36+
else
37+
break
38+
fi
39+
done
40+
41+
if [[ "$REBASEABLE" != "true" ]] ; then
42+
echo "GitHub doesn't think that the PR is rebaseable!"
43+
exit 1
44+
fi
2645

2746
BASE_REPO=$(echo "$pr_resp" | jq -r .base.repo.full_name)
2847
BASE_BRANCH=$(echo "$pr_resp" | jq -r .base.ref)
2948

3049
USER_LOGIN=$(jq -r ".comment.user.login" "$GITHUB_EVENT_PATH")
3150

3251
user_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
33-
"${URI}/users/${USER_LOGIN}")
52+
"${URI}/users/${USER_LOGIN}")
3453

3554
USER_NAME=$(echo "$user_resp" | jq -r ".name")
3655
if [[ "$USER_NAME" == "null" ]]; then
@@ -43,12 +62,6 @@ if [[ "$USER_EMAIL" == "null" ]]; then
4362
USER_EMAIL="$USER_LOGIN@users.noreply.github.com"
4463
fi
4564

46-
if [[ "$(echo "$pr_resp" | jq -r .rebaseable)" != "true" ]]; then
47-
echo "GitHub doesn't think that the PR is rebaseable!"
48-
echo "API response: $pr_resp"
49-
exit 1
50-
fi
51-
5265
if [[ -z "$BASE_BRANCH" ]]; then
5366
echo "Cannot get base branch information for PR #$PR_NUMBER!"
5467
exit 1

0 commit comments

Comments
 (0)