From 6251c0a09445a84b6b4565f96c82777e88411a50 Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Wed, 20 Mar 2019 10:05:38 -0400 Subject: [PATCH] adding title and body --- README.md | 2 ++ pull-request.sh | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 98ac141..16fb2b6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Environment variables include: - **BRANCH_PREFIX**: the prefix to filter to. If the branch doesn't start with the prefix, it will be ignored - **PULL_REQUEST_BRANCH**: the branch to issue the pull request to. Defaults to master. + - **PULL_REQUEST_BODY**: the body for the pull request (optional) + - **PULL_REQUEST_TITLE**: the title for the pull request (optional) ## Example use Case: Update Registry diff --git a/pull-request.sh b/pull-request.sh index 17c0635..ab2e72a 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -46,10 +46,12 @@ 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 # Check if the branch already has a pull request open - DATA="{\"base\":\"${TARGET}\", \"head\":\"${SOURCE}\"}" + 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}" @@ -60,9 +62,6 @@ create_pull_request() { # Option 2: Open a new pull request else - TITLE="Update container ${SOURCE}" - BODY="This is an automated pull request to update the container collection ${SOURCE}" - # Post the pull request DATA="{\"title\":\"${TITLE}\", \"base\":\"${TARGET}\", \"head\":\"${SOURCE}\"}" echo "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}" @@ -95,7 +94,7 @@ main () { BRANCH=$(jq --raw-output .ref "${GITHUB_EVENT_PATH}"); BRANCH=$(echo "${BRANCH/refs\/heads\//}") echo "Found branch $BRANCH" - + # If it's to the target branch, ignore it if [[ "${BRANCH}" == "${PULL_REQUEST_BRANCH}" ]]; then echo "Target and current branch are identical (${BRANCH}), skipping." @@ -106,7 +105,22 @@ main () { # Ensure we have a GitHub token check_credentials - create_pull_request $BRANCH $PULL_REQUEST_BRANCH + + # Pull request body (optional) + if [ -z "${PULL_REQUEST_BODY}" ]; then + echo "No pull request body is set, will use default." + PULL_REQUEST_BODY="This is an automated pull request to update the container collection ${BRANCH}" + echo "Pull request body is ${PULL_REQUEST_BODY}" + fi + + # Pull request title (optional) + if [ -z "${PULL_REQUEST_TITLE}" ]; then + echo "No pull request title is set, will use default." + PULL_REQUEST_TITLE="Update container ${BRANCH}" + echo "Pull request title is ${PULL_REQUEST_TITLE}" + fi + + create_pull_request $BRANCH $PULL_REQUEST_BRANCH $PULL_REQUEST_BODY $PULL_REQUEST_TITLE fi