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

Retry if the PR is unrebaseable #75

Merged
merged 2 commits into from
May 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,36 @@ 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" || "$i" == "$MAX_RETRIES" ]] ; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no need to check for i value. Not even sure if it's still available here. 🤔

Suggested change
if [[ "$REBASEABLE" != "true" || "$i" == "$MAX_RETRIES" ]] ; then
if [[ "$REBASEABLE" != "true" ]] ; then

Copy link
Contributor Author

@ddzero2c ddzero2c May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it no need to check for i.

e4987e7

echo "GitHub doesn't think that the PR is rebaseable!"
echo "API response: $pr_resp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not print the response here. It was a CVE https://bugs.chromium.org/p/project-zero/issues/detail?id=2070

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit 1
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 All @@ -43,12 +63,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
Expand Down