From 91d52b545f82cb88e86c3002a443de22df77fa16 Mon Sep 17 00:00:00 2001 From: Andrii Bodnar Date: Wed, 18 Sep 2024 14:42:42 +0300 Subject: [PATCH] fix: issues related to checking for the existing pull requests (#250) --- entrypoint.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9794020..e71015d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -88,6 +88,7 @@ create_pull_request() { REPO_URL="https://api.${INPUT_GITHUB_BASE_URL}/repos/${GITHUB_REPOSITORY}" fi + ORG_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1) PULLS_URL="${REPO_URL}/pulls" 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() { fi fi - PULL_REQUESTS_QUERY_PARAMS="?base=${BASE_BRANCH}&head=${BRANCH}" + pull_requests_response=$(curl -sSL -w "%{http_code}" -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${PULLS_URL}?base=${BASE_BRANCH}&head=${ORG_NAME}:${BRANCH}") + http_code="${pull_requests_response: -3}" + response_body="${pull_requests_response%???}" - PULL_REQUESTS=$(echo "$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${PULLS_URL}${PULL_REQUESTS_QUERY_PARAMS}")" | jq --raw-output '.[] | .head.ref ') + if [ "$http_code" -ne 200 ]; then + echo "Error: Failed to fetch pull requests. HTTP status: $http_code" + echo "Response: $response_body" + exit 1 + fi + + PULL_REQUESTS=$(echo "$response_body" | jq --raw-output '.[] | .head.ref') if echo "$PULL_REQUESTS" | grep -xq "$BRANCH"; then echo "PULL REQUEST ALREADY EXIST"