adding maintainer can modify
Signed-off-by: vsoch <vsochat@stanford.edu>
This commit is contained in:
@@ -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_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_BODY | the body for the pull request | false | |
|
||||||
| PULL REQUEST_TITLE | the title 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 `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.
|
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.
|
||||||
|
|||||||
@@ -49,16 +49,10 @@ create_pull_request() {
|
|||||||
TARGET="$(echo -n "${2}" | jq --raw-input --slurp ".")" # pull request TO this target
|
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
|
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
|
TITLE="$(echo -n "${4}" | jq --raw-input --slurp ".")" # pull request title
|
||||||
|
DRAFT="${5}" # pull request draft?
|
||||||
# JSON boolean
|
MODIFY="${6}" # maintainer can modify
|
||||||
if [[ "${5}" == "true" ]]; then # if PRs are draft
|
|
||||||
DRAFT="true";
|
|
||||||
else
|
|
||||||
DRAFT="false";
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the branch already has a pull request open
|
# Check if the branch already has a pull request open
|
||||||
|
|
||||||
DATA="{\"base\":${TARGET}, \"head\":${SOURCE}, \"body\":${BODY}}"
|
DATA="{\"base\":${TARGET}, \"head\":${SOURCE}, \"body\":${BODY}}"
|
||||||
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X GET --data "${DATA}" ${PULLS_URL})
|
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')
|
PR=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref')
|
||||||
@@ -71,7 +65,7 @@ create_pull_request() {
|
|||||||
# Option 2: Open a new pull request
|
# Option 2: Open a new pull request
|
||||||
else
|
else
|
||||||
# Post the pull request
|
# 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"
|
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}
|
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}
|
||||||
echo $?
|
echo $?
|
||||||
@@ -98,6 +92,7 @@ main () {
|
|||||||
fi
|
fi
|
||||||
printf "Pull requests will go to ${PULL_REQUEST_BRANCH}\n"
|
printf "Pull requests will go to ${PULL_REQUEST_BRANCH}\n"
|
||||||
|
|
||||||
|
# Pull request draft
|
||||||
if [ -z "${PULL_REQUEST_DRAFT}" ]; then
|
if [ -z "${PULL_REQUEST_DRAFT}" ]; then
|
||||||
printf "No explicit preference for draft PR: created PRs will be normal PRs.\n"
|
printf "No explicit preference for draft PR: created PRs will be normal PRs.\n"
|
||||||
PULL_REQUEST_DRAFT="false"
|
PULL_REQUEST_DRAFT="false"
|
||||||
@@ -106,6 +101,15 @@ main () {
|
|||||||
PULL_REQUEST_DRAFT="true"
|
PULL_REQUEST_DRAFT="true"
|
||||||
fi
|
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
|
# The user is allowed to explicitly set the name of the branch
|
||||||
if [ -z "${PULL_REQUEST_FROM_BRANCH}" ]; then
|
if [ -z "${PULL_REQUEST_FROM_BRANCH}" ]; then
|
||||||
printf "PULL_REQUEST_FROM_BRANCH is not set, checking branch in payload.\n"
|
printf "PULL_REQUEST_FROM_BRANCH is not set, checking branch in payload.\n"
|
||||||
@@ -149,7 +153,8 @@ main () {
|
|||||||
fi
|
fi
|
||||||
printf "Pull request title is ${PULL_REQUEST_TITLE}\n"
|
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
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user