@@ -21,16 +21,35 @@ URI=https://api.github.com
21
21
API_HEADER=" Accept: application/vnd.github.v3+json"
22
22
AUTH_HEADER=" Authorization: token $GITHUB_TOKEN "
23
23
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
26
45
27
46
BASE_REPO=$( echo " $pr_resp " | jq -r .base.repo.full_name)
28
47
BASE_BRANCH=$( echo " $pr_resp " | jq -r .base.ref)
29
48
30
49
USER_LOGIN=$( jq -r " .comment.user.login" " $GITHUB_EVENT_PATH " )
31
50
32
51
user_resp=$( curl -X GET -s -H " ${AUTH_HEADER} " -H " ${API_HEADER} " \
33
- " ${URI} /users/${USER_LOGIN} " )
52
+ " ${URI} /users/${USER_LOGIN} " )
34
53
35
54
USER_NAME=$( echo " $user_resp " | jq -r " .name" )
36
55
if [[ " $USER_NAME " == " null" ]]; then
@@ -43,12 +62,6 @@ if [[ "$USER_EMAIL" == "null" ]]; then
43
62
USER_EMAIL=" $USER_LOGIN @users.noreply.github.com"
44
63
fi
45
64
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
-
52
65
if [[ -z " $BASE_BRANCH " ]]; then
53
66
echo " Cannot get base branch information for PR #$PR_NUMBER !"
54
67
exit 1
0 commit comments