From e9cc2a3f41aadd3391c32bedf4a0c1c410655c0a Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 13:47:52 -0600 Subject: [PATCH 01/13] adding maintainer can modify Signed-off-by: vsoch --- README.md | 9 +++++++-- pull-request.sh | 25 +++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2a973bf..f9d5511 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,14 @@ Unlike standard actions, this action just uses variables from the environment. | PULL_REQUEST_FROM_BRANCH | if a branch isn't found in your GitHub payload, use this branch | false | | | PULL_REQUEST_BODY | the body for the pull request | false | | | PULL REQUEST_TITLE | the title for the pull request | false | | -| PULL REQUEST_DRAFT | should this be a draft PR? | false | false | +| PULL REQUEST_DRAFT | should this be a draft PR? | false | unset | +| MAINTAINER_CANT_MODIFY | Do not allow the maintainer to modify the PR | false | unset | -All booleans should be lowercase. +For `PULL_REQUEST_DRAFT` and `MAINTAINER_CAN_MODIFY`, these are treated as environment +booleans. If they are defined in the environment, they trigger the "true" condition. E.g.,: + + - Define `MAINTAINER_CANT_MODIFY` if you don't want the maintainer to be able to modify the pull request. + - Define `PULL_REQUEST_DRAFT` if you want the PR to be a draft. The `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open the pull request. The example is [deployed here](https://github.com/vsoch/pull-request-action-example) with an example opened (and merged) [pull request here](https://github.com/vsoch/pull-request-action-example/pull/1) if needed. diff --git a/pull-request.sh b/pull-request.sh index 18146ee..9ae6fd2 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -49,16 +49,10 @@ create_pull_request() { 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 - - # JSON boolean - if [[ "${5}" == "true" ]]; then # if PRs are draft - DRAFT="true"; - else - DRAFT="false"; - fi + DRAFT="${5}" # pull request draft? + MODIFY="${6}" # maintainer can modify # 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') @@ -71,7 +65,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}, \"maintainer_can_modify\":${MODIFY}}" printf "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}\n" curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL} echo $? @@ -98,6 +92,7 @@ main () { fi printf "Pull requests will go to ${PULL_REQUEST_BRANCH}\n" + # Pull request draft if [ -z "${PULL_REQUEST_DRAFT}" ]; then printf "No explicit preference for draft PR: created PRs will be normal PRs.\n" PULL_REQUEST_DRAFT="false" @@ -106,6 +101,15 @@ main () { PULL_REQUEST_DRAFT="true" fi + # Maintainer can modify, defaults to CAN, unless user sets MAINTAINER_CANT_MODIFY + if [ -z "${MAINTAINER_CANT_MODIFY}" ]; then + printf "No explicit preference for maintainer being able to modify: default is true.\n" + MODIFY="true" + else + printf "Environment variable MAINTAINER_CANT_MODIFY set to a value: maintainer will not be able to modify.\n" + MODIFY="false" + fi + # The user is allowed to explicitly set the name of the branch if [ -z "${PULL_REQUEST_FROM_BRANCH}" ]; then printf "PULL_REQUEST_FROM_BRANCH is not set, checking branch in payload.\n" @@ -149,7 +153,8 @@ main () { fi printf "Pull request title is ${PULL_REQUEST_TITLE}\n" - create_pull_request "${BRANCH}" "${PULL_REQUEST_BRANCH}" "${PULL_REQUEST_BODY}" "${PULL_REQUEST_TITLE}" "${PULL_REQUEST_DRAFT}" + create_pull_request "${BRANCH}" "${PULL_REQUEST_BRANCH}" "${PULL_REQUEST_BODY}" \ + "${PULL_REQUEST_TITLE}" "${PULL_REQUEST_DRAFT}" "${MODIFY}" fi From 125f29f4723a2865d4250bf81ba243480c8aec0c Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:07:00 -0600 Subject: [PATCH 02/13] adding ability to assign people to PR Signed-off-by: vsoch --- README.md | 5 +++++ pull-request.sh | 31 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9d5511..2cf103e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Unlike standard actions, this action just uses variables from the environment. | PULL REQUEST_TITLE | the title for the pull request | false | | | PULL REQUEST_DRAFT | should this be a draft PR? | false | unset | | MAINTAINER_CANT_MODIFY | Do not allow the maintainer to modify the PR | false | unset | +| PULL_REQUEST_ASSIGNEES | A list (string with spaces) of users to assign | false | unset | For `PULL_REQUEST_DRAFT` and `MAINTAINER_CAN_MODIFY`, these are treated as environment booleans. If they are defined in the environment, they trigger the "true" condition. E.g.,: @@ -49,6 +50,10 @@ booleans. If they are defined in the environment, they trigger the "true" condit - Define `MAINTAINER_CANT_MODIFY` if you don't want the maintainer to be able to modify the pull request. - Define `PULL_REQUEST_DRAFT` if you want the PR to be a draft. +For `PULL_REQUEST_ASSIGNEES`, you can provide a string of one or more GitHub usernames to +assign to the issue. Note that only users with push access can add assigness to +an issue or PR, they are ignored otherwise. + The `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open the pull request. The example is [deployed here](https://github.com/vsoch/pull-request-action-example) with an example opened (and merged) [pull request here](https://github.com/vsoch/pull-request-action-example/pull/1) if needed. diff --git a/pull-request.sh b/pull-request.sh index 9ae6fd2..f41bf3e 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -16,6 +16,7 @@ HEADER="${HEADER}; application/vnd.github.antiope-preview+json; application/vnd. # URLs REPO_URL="${BASE}/repos/${GITHUB_REPOSITORY}" +ISSUE_URL=${REPO_URL}/issues PULLS_URL=$REPO_URL/pulls ################################################################################ @@ -51,6 +52,7 @@ create_pull_request() { TITLE="$(echo -n "${4}" | jq --raw-input --slurp ".")" # pull request title DRAFT="${5}" # pull request draft? MODIFY="${6}" # maintainer can modify + ASSIGNEES="$(echo -n "${7}" | jq --raw-input --slurp ".")" # Check if the branch already has a pull request open DATA="{\"base\":${TARGET}, \"head\":${SOURCE}, \"body\":${BODY}}" @@ -67,8 +69,20 @@ create_pull_request() { # Post the pull request DATA="{\"title\":${TITLE}, \"body\":${BODY}, \"base\":${TARGET}, \"head\":${SOURCE}, \"draft\":${DRAFT}, \"maintainer_can_modify\":${MODIFY}}" printf "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}\n" - curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL} - echo $? + RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}) + NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.[] | .number') + printf "Number opened for PR is ${NUMBER}\n" + + # If there are assignees, assigm them to it + if [[ "${ASSIGNEES}" != "" ]]; then + printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" + + # POST /repos/:owner/:repo/issues/:issue_number/assignees + DATA="{\"assignees\":\"${ASSIGNEES}\"}" + ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" + curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL}) + echo $? + fi fi } @@ -110,6 +124,16 @@ main () { MODIFY="false" fi + # Assignees + ASSIGNEES="" + if [ -z "${PULL_REQUEST_ASSIGNEES}" ]; then + printf "PULL_REQUEST_ASSIGNEES is not set, no assignees.\n" + else + printf "PULL_REQUEST_ASSIGNEES is set, ${PULL_REQUEST_ASSIGNEES}\n" + ASSIGNEES="${PULL_REQUEST_ASSIGNEES}" + fi + + # The user is allowed to explicitly set the name of the branch if [ -z "${PULL_REQUEST_FROM_BRANCH}" ]; then printf "PULL_REQUEST_FROM_BRANCH is not set, checking branch in payload.\n" @@ -154,7 +178,8 @@ main () { printf "Pull request title is ${PULL_REQUEST_TITLE}\n" create_pull_request "${BRANCH}" "${PULL_REQUEST_BRANCH}" "${PULL_REQUEST_BODY}" \ - "${PULL_REQUEST_TITLE}" "${PULL_REQUEST_DRAFT}" "${MODIFY}" + "${PULL_REQUEST_TITLE}" "${PULL_REQUEST_DRAFT}" "${MODIFY}" \ + "${ASSIGNEES}" fi From c4372cd5243f727468b82c7cda7cda5bc62cefe5 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:18:42 -0600 Subject: [PATCH 03/13] fixing print of return value and syntax error Signed-off-by: vsoch --- pull-request.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pull-request.sh b/pull-request.sh index f41bf3e..68b94f0 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -70,6 +70,8 @@ create_pull_request() { DATA="{\"title\":${TITLE}, \"body\":${BODY}, \"base\":${TARGET}, \"head\":${SOURCE}, \"draft\":${DRAFT}, \"maintainer_can_modify\":${MODIFY}}" printf "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}\n" RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}) + RETVAL=$? + printf "Pull request return code: ${RETVAL}\n" NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.[] | .number') printf "Number opened for PR is ${NUMBER}\n" @@ -80,8 +82,8 @@ create_pull_request() { # POST /repos/:owner/:repo/issues/:issue_number/assignees DATA="{\"assignees\":\"${ASSIGNEES}\"}" ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" - curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL}) - echo $? + curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL} + printf "$?\n" fi fi } From d0166ffab5e6752cdfcc0cf1ee327e8d35cabe03 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:24:24 -0600 Subject: [PATCH 04/13] updating pull request to use return code to determine to assign folks Signed-off-by: vsoch --- pull-request.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pull-request.sh b/pull-request.sh index 68b94f0..909ae27 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -72,13 +72,16 @@ create_pull_request() { RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}) RETVAL=$? printf "Pull request return code: ${RETVAL}\n" - NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.[] | .number') - printf "Number opened for PR is ${NUMBER}\n" + echo ${RESPONSE} - # If there are assignees, assigm them to it - if [[ "${ASSIGNEES}" != "" ]]; then + # If there are assignees and we were successful to open, assigm them to it + if [[ "${ASSIGNEES}" != "" ]] && [[ "${RETVAL}" == "0" ]]; then + + NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.[] | .number') + printf "Number opened for PR is ${NUMBER}\n" printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" + # POST /repos/:owner/:repo/issues/:issue_number/assignees DATA="{\"assignees\":\"${ASSIGNEES}\"}" ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" @@ -168,14 +171,14 @@ main () { # 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}" + PULL_REQUEST_BODY="This is an automated pull request to update from branch ${BRANCH}" fi printf "Pull request body is ${PULL_REQUEST_BODY}\n" # Pull request title (optional) if [ -z "${PULL_REQUEST_TITLE}" ]; then printf "No pull request title is set, will use default.\n" - PULL_REQUEST_TITLE="Update container ${BRANCH}" + PULL_REQUEST_TITLE="Update from ${BRANCH}" fi printf "Pull request title is ${PULL_REQUEST_TITLE}\n" From df89c5fb9e9eb17dae164e8fb67958ad8088716e Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:28:35 -0600 Subject: [PATCH 05/13] update to use .number Signed-off-by: vsoch --- pull-request.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pull-request.sh b/pull-request.sh index 909ae27..83eca52 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -77,7 +77,7 @@ create_pull_request() { # If there are assignees and we were successful to open, assigm them to it if [[ "${ASSIGNEES}" != "" ]] && [[ "${RETVAL}" == "0" ]]; then - NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.[] | .number') + NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" From 09f5606222f4325e59975da33a49b570f0f41bbd Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:30:22 -0600 Subject: [PATCH 06/13] update to use .number Signed-off-by: vsoch --- pull-request.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/pull-request.sh b/pull-request.sh index 83eca52..5d0c6da 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -72,7 +72,6 @@ create_pull_request() { RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}) RETVAL=$? printf "Pull request return code: ${RETVAL}\n" - echo ${RESPONSE} # If there are assignees and we were successful to open, assigm them to it if [[ "${ASSIGNEES}" != "" ]] && [[ "${RETVAL}" == "0" ]]; then From 8638d1b6f16052347680b5ec9d7f0aac546ac2b1 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:35:59 -0600 Subject: [PATCH 07/13] need to echo response Signed-off-by: vsoch --- pull-request.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pull-request.sh b/pull-request.sh index 5d0c6da..c31b7e2 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -76,6 +76,7 @@ create_pull_request() { # If there are assignees and we were successful to open, assigm them to it if [[ "${ASSIGNEES}" != "" ]] && [[ "${RETVAL}" == "0" ]]; then + echo "${REPONSE}" NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" From 37a2b853329f5a2889df3655783282ebb338faaa Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:38:47 -0600 Subject: [PATCH 08/13] trying again Signed-off-by: vsoch --- pull-request.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pull-request.sh b/pull-request.sh index c31b7e2..01e8e76 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -76,7 +76,7 @@ create_pull_request() { # If there are assignees and we were successful to open, assigm them to it if [[ "${ASSIGNEES}" != "" ]] && [[ "${RETVAL}" == "0" ]]; then - echo "${REPONSE}" + echo "${RESPONSE}" NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" From 906c9693bfd3adf2e02fef6113cb0c48e4e37c2a Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:43:26 -0600 Subject: [PATCH 09/13] need to parse assignees Signed-off-by: vsoch --- pull-request.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pull-request.sh b/pull-request.sh index 01e8e76..8160fdf 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -79,11 +79,13 @@ create_pull_request() { echo "${RESPONSE}" NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" + + # Parse assignees into a list + ASSIGNEES=$(echo $ASSIGNEES | sed -e 's/\(\w*\)/,"\1"/g' | cut -d , -f 2-) printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" - # POST /repos/:owner/:repo/issues/:issue_number/assignees - DATA="{\"assignees\":\"${ASSIGNEES}\"}" + DATA="{\"assignees\":[${ASSIGNEES}]}" ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL} printf "$?\n" From 617744b952a69aee63b2d60a46c86ad47f633e3c Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 14:52:58 -0600 Subject: [PATCH 10/13] fail no matter what Signed-off-by: vsoch --- pull-request.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pull-request.sh b/pull-request.sh index 8160fdf..68be2f4 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -86,9 +86,11 @@ create_pull_request() { # POST /repos/:owner/:repo/issues/:issue_number/assignees DATA="{\"assignees\":[${ASSIGNEES}]}" + echo "${DATA}" ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL} printf "$?\n" + exit 1; fi fi } From 6795aa743d0e4ace6097e0a911998faad19542f6 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 15:20:50 -0600 Subject: [PATCH 11/13] fix trailing slash Signed-off-by: vsoch --- pull-request.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pull-request.sh b/pull-request.sh index 68be2f4..3518fc9 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -80,7 +80,11 @@ create_pull_request() { NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" - # Parse assignees into a list + # Remove trailing slashes + ASSIGNEES="${ASSIGNEES%\"}" + ASSIGNEES="${ASSIGNEES#\"}" + + # Parse assignees into a list ASSIGNEES=$(echo $ASSIGNEES | sed -e 's/\(\w*\)/,"\1"/g' | cut -d , -f 2-) printf "Attempting to assign ${ASSIGNEES} to ${PR} with number ${NUMBER}" From 90f97d7ca1993c9b01dcc08b6f1f30c720f2feee Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 15:35:22 -0600 Subject: [PATCH 12/13] last change to add example Signed-off-by: vsoch --- examples/assignees-example.yml | 17 +++++++++++++++++ pull-request.sh | 8 +++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 examples/assignees-example.yml diff --git a/examples/assignees-example.yml b/examples/assignees-example.yml new file mode 100644 index 0000000..6db7db3 --- /dev/null +++ b/examples/assignees-example.yml @@ -0,0 +1,17 @@ +name: Pull Request on Branch Push +on: + push: + branches-ignore: + - devel +jobs: + auto-pull-request: + name: PullRequestAction + runs-on: ubuntu-latest + steps: + - name: pull-request-action + uses: vsoch/pull-request-action@add/assignees + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH_PREFIX: "update/" + PULL_REQUEST_BRANCH: "master" + PULL_REQUEST_ASSIGNEES: vsoch diff --git a/pull-request.sh b/pull-request.sh index 3518fc9..12111a7 100755 --- a/pull-request.sh +++ b/pull-request.sh @@ -37,7 +37,7 @@ check_events_json() { if [[ ! -f "${GITHUB_EVENT_PATH}" ]]; then printf "Cannot find Github events file at ${GITHUB_EVENT_PATH}\n"; - exit 1; + exit 1 fi printf "Found ${GITHUB_EVENT_PATH}\n"; @@ -80,9 +80,8 @@ create_pull_request() { NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number') printf "Number opened for PR is ${NUMBER}\n" - # Remove trailing slashes - ASSIGNEES="${ASSIGNEES%\"}" - ASSIGNEES="${ASSIGNEES#\"}" + # Remove leading and trailing quotes + ASSIGNEES=$(echo "$ASSIGNEES" | sed -e 's/^"//' -e 's/"$//') # Parse assignees into a list ASSIGNEES=$(echo $ASSIGNEES | sed -e 's/\(\w*\)/,"\1"/g' | cut -d , -f 2-) @@ -94,7 +93,6 @@ create_pull_request() { ASSIGNEES_URL="${ISSUE_URL}/${NUMBER}/assignees" curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${ASSIGNEES_URL} printf "$?\n" - exit 1; fi fi } From c3a7ec260e0c72c7c7155a5ae6c5913cc34560a8 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 18 Mar 2020 15:51:49 -0600 Subject: [PATCH 13/13] update version of example Signed-off-by: vsoch --- README.md | 2 +- examples/assignees-example.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2cf103e..cc12fab 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Unlike standard actions, this action just uses variables from the environment. | MAINTAINER_CANT_MODIFY | Do not allow the maintainer to modify the PR | false | unset | | PULL_REQUEST_ASSIGNEES | A list (string with spaces) of users to assign | false | unset | -For `PULL_REQUEST_DRAFT` and `MAINTAINER_CAN_MODIFY`, these are treated as environment +For `PULL_REQUEST_DRAFT` and `MAINTAINER_CANT_MODIFY`, these are treated as environment booleans. If they are defined in the environment, they trigger the "true" condition. E.g.,: - Define `MAINTAINER_CANT_MODIFY` if you don't want the maintainer to be able to modify the pull request. diff --git a/examples/assignees-example.yml b/examples/assignees-example.yml index 6db7db3..6a709e9 100644 --- a/examples/assignees-example.yml +++ b/examples/assignees-example.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: pull-request-action - uses: vsoch/pull-request-action@add/assignees + uses: vsoch/pull-request-action@1.0.3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_PREFIX: "update/"