Fix a few bugs with the create_buildkite_pr_build.sh script (#11872)
* Fix a few bugs with the create_buildkite_pr_build.sh script.
This will ${PULL_REQUEST_ID:-} will allow for PULL_REQUEST_ID to be not set in
the if statement so the script won't fail.
It fixes the jq lookups on GITHUB_EVENT_PATH for setting:
PULL_REQUEST_ID
COMMENT_USER_LOGIN
COMMENT_URL
from GITHUB_EVENT_PATH
It fixes the jq lookups on
* Add in missing dub quotes
This commit is contained in:
parent
174950a827
commit
9ccd06bfa5
1 changed files with 14 additions and 14 deletions
|
|
@ -28,11 +28,11 @@ if [[ -z "$GITHUB_TOKEN" ]]; then
|
|||
fi
|
||||
|
||||
# Check if PULL_REQUEST_ID is empty or null and try to set it
|
||||
if [[ -z "${PULL_REQUEST_ID}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
PULL_REQUEST_ID=$(jq -r .event.issue.number "${GITHUB_EVENT_PATH}")
|
||||
elif [[ -z "${PULL_REQUEST_ID}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
PULL_REQUEST_ID=$(jq -r .event.number "${GITHUB_EVENT_PATH}")
|
||||
elif [[ -z "${PULL_REQUEST_ID}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
if [[ -z "${PULL_REQUEST_ID:-}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
PULL_REQUEST_ID=$(jq -r ".issue.number" "${GITHUB_EVENT_PATH}")
|
||||
elif [[ -z "${PULL_REQUEST_ID:-}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
PULL_REQUEST_ID=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
|
||||
elif [[ -z "${PULL_REQUEST_ID:-}" || "${PULL_REQUEST_ID}" == "null" ]]; then
|
||||
echo "Failed to determine PR Number."
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -47,15 +47,15 @@ AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
|
|||
PULL_REQUEST_INFO=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
|
||||
"${URI}/repos/${GITHUB_REPOSITORY}/pulls/${PULL_REQUEST_ID}")
|
||||
|
||||
PULL_REQUEST_BASE_REPO=$(echo "${PULL_REQUEST_INFO}" | jq -r .base.repo.full_name)
|
||||
PULL_REQUEST_BASE_BRANCH=$(echo "${PULL_REQUEST_INFO}" | jq -r .base.ref)
|
||||
PULL_REQUEST_BASE_REPO=$(echo "${PULL_REQUEST_INFO}" | jq -r ".base.repo.full_name")
|
||||
PULL_REQUEST_BASE_BRANCH=$(echo "${PULL_REQUEST_INFO}" | jq -r ".base.ref")
|
||||
|
||||
PULL_REQUEST_HEAD_REPO=$(echo "${PULL_REQUEST_INFO}" | jq -r .head.repo.full_name)
|
||||
PULL_REQUEST_HEAD_BRANCH=$(echo "${PULL_REQUEST_INFO}" | jq -r .head.ref)
|
||||
PULL_REQUEST_HEAD_SHA=$(echo "${PULL_REQUEST_INFO}" | jq -r .head.sha)
|
||||
PULL_REQUEST_HEAD_REPO=$(echo "${PULL_REQUEST_INFO}" | jq -r ".head.repo.full_name")
|
||||
PULL_REQUEST_HEAD_BRANCH=$(echo "${PULL_REQUEST_INFO}" | jq -r ".head.ref")
|
||||
PULL_REQUEST_HEAD_SHA=$(echo "${PULL_REQUEST_INFO}" | jq -r ".head.sha")
|
||||
|
||||
# Gather information about the pull request user
|
||||
PULL_REQUEST_USER_LOGIN=$(echo "${PULL_REQUEST_INFO}" | jq -r .user.login)
|
||||
PULL_REQUEST_USER_LOGIN=$(echo "${PULL_REQUEST_INFO}" | jq -r ".user.login")
|
||||
PULL_REQUEST_USER_INFO=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
|
||||
"${URI}/users/${PULL_REQUEST_USER_LOGIN}")
|
||||
|
||||
|
|
@ -71,11 +71,11 @@ if [[ "${PULL_REQUEST_USER_EMAIL}" == "null" ]]; then
|
|||
fi
|
||||
|
||||
# Set Buildkite pipeline variables
|
||||
COMMENT_USER_LOGIN=$(jq -r ".event.comment.user.login" "${GITHUB_EVENT_PATH}")
|
||||
COMMENT_USER_LOGIN=$(jq -r ".comment.user.login" "${GITHUB_EVENT_PATH}")
|
||||
ORG_SLUG=$(echo "${PIPELINE}" | cut -d'/' -f1)
|
||||
PIPELINE_SLUG=$(echo "${PIPELINE}" | cut -d'/' -f2)
|
||||
MESSAGE_URL=$(jq -r ".event.issue.html_url" "${GITHUB_EVENT_PATH}")
|
||||
MESSAGE="Build triggered from GitHub Action by ${COMMENT_USER_LOGIN} on ${MESSAGE_URL} for ${PULL_REQUEST_USER_LOGIN}"
|
||||
COMMENT_URL=$(jq -r ".comment.html_url" "${GITHUB_EVENT_PATH}")
|
||||
MESSAGE="Build triggered from GitHub Action by ${COMMENT_USER_LOGIN} on ${COMMENT_URL} for ${PULL_REQUEST_USER_LOGIN}"
|
||||
|
||||
# Build JSON payload
|
||||
JSON=$(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue