diff --git a/pull-request.sh b/pull-request.sh index 1eb038a..4a55f93 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -39,20 +39,27 @@ check_events_json() { exit 1; fi echo "Found ${GITHUB_EVENT_PATH}"; - + } create_pull_request() { - SOURCE="${1}" # from this branch - TARGET="${2}" # pull request TO this target - BODY="${3}" # this is the content of the message - TITLE="${4}" # pull request title - DRAFT="${5}" # if PRs are draft + # JSON strings + SOURCE="$(echo -n "${1}" | jq --raw-input --slurp ".")" # from this branch + TARGET="$(echo -n "${2}" | jq --raw-input --slurp ".")" # pull request TO this target + BODY="$(echo -n "${3}" | jq --raw-input --slurp ".")" # this is the content of the message + TITLE="$(echo -n "${4}" | jq --raw-input --slurp ".")" # pull request title - # Check if the branch already has a pull request open + # JSON boolean + if [[ "${5}" == "true" ]]; then # if PRs are draft + DRAFT="true"; + else + DRAFT="false"; + fi - DATA="{\"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"body\":\"${BODY}\"}" + # Check if the branch already has a pull request open + + DATA="{\"base\":${TARGET}, \"head\":${SOURCE}, \"body\":${BODY}}" RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X GET --data "${DATA}" ${PULLS_URL}) PR=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref') echo "Response ref: ${PR}" @@ -64,7 +71,7 @@ create_pull_request() { # Option 2: Open a new pull request else # Post the pull request - DATA="{\"title\":\"${TITLE}\", \"body\":\"${BODY}\", \"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"draft\":\"${DRAFT}\"}" + DATA="{\"title\":${TITLE}, \"body\":${BODY}, \"base\":${TARGET}, \"head\":${SOURCE}, \"draft\":${DRAFT}}" echo "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}" curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL} echo $? @@ -121,7 +128,7 @@ main () { PULL_REQUEST_BODY="This is an automated pull request to update the container collection ${BRANCH}" fi echo "Pull request body is ${PULL_REQUEST_BODY}" - + # Pull request title (optional) if [ -z "${PULL_REQUEST_TITLE}" ]; then echo "No pull request title is set, will use default."