Skip to content

Commit 91d52b5

Browse files
fix: issues related to checking for the existing pull requests (#250)
1 parent 3399249 commit 91d52b5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

entrypoint.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ create_pull_request() {
8888
REPO_URL="https://api.${INPUT_GITHUB_BASE_URL}/repos/${GITHUB_REPOSITORY}"
8989
fi
9090

91+
ORG_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1)
9192
PULLS_URL="${REPO_URL}/pulls"
9293

9394
auth_status=$(curl -sL --write-out '%{http_code}' --output /dev/null -H "${AUTH_HEADER}" -H "${HEADER}" "${PULLS_URL}")
@@ -110,9 +111,17 @@ create_pull_request() {
110111
fi
111112
fi
112113

113-
PULL_REQUESTS_QUERY_PARAMS="?base=${BASE_BRANCH}&head=${BRANCH}"
114+
pull_requests_response=$(curl -sSL -w "%{http_code}" -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${PULLS_URL}?base=${BASE_BRANCH}&head=${ORG_NAME}:${BRANCH}")
115+
http_code="${pull_requests_response: -3}"
116+
response_body="${pull_requests_response%???}"
114117

115-
PULL_REQUESTS=$(echo "$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${PULLS_URL}${PULL_REQUESTS_QUERY_PARAMS}")" | jq --raw-output '.[] | .head.ref ')
118+
if [ "$http_code" -ne 200 ]; then
119+
echo "Error: Failed to fetch pull requests. HTTP status: $http_code"
120+
echo "Response: $response_body"
121+
exit 1
122+
fi
123+
124+
PULL_REQUESTS=$(echo "$response_body" | jq --raw-output '.[] | .head.ref')
116125

117126
if echo "$PULL_REQUESTS" | grep -xq "$BRANCH"; then
118127
echo "PULL REQUEST ALREADY EXIST"

0 commit comments

Comments
 (0)