first test to add outputs

Signed-off-by: vsoch <vsochat@stanford.edu>
This commit is contained in:
vsoch
2020-03-25 09:55:39 -06:00
parent 702ab9c078
commit aaed200ec8
4 changed files with 44 additions and 3 deletions

View File

@@ -14,5 +14,6 @@ represented by the pull requests that fixed them. Critical items to know are:
Versions correspond with GitHub releases that can be referenced with @ using actions.
## [master](https://github.com/vsoch/pull-request-action/tree/master) (master)
- output and environment variables for PR number and return codes (1.0.5)
- added support for reviewer (individual and team) assignments (1.0.4)
- added support for maintainer can modify and assignees (1.0.3)

View File

@@ -29,7 +29,7 @@ jobs:
PULL_REQUEST_BRANCH: "master"
```
## Environment Variables
## Environment Variable Inputs
Unlike standard actions, this action just uses variables from the environment.
@@ -60,6 +60,19 @@ 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.
## Outputs
The action sets a few useful output and environment variables. An output can
be referenced later as `${{ steps.<stepname>.outputs.<output-name> }}`.
An environment variable of course can be referenced as you usually would.
| Name | Description | Environment |
|------|-------------|-------------|
| pull_request_number |If the pull request is opened, this is the number for it. | PULL_REQUEST_NUMBER |
| pull_request_url |If the pull request is opened, the html url for it. | PULL_REQUEST_URL |
| pull_request_return_code | Return code for the pull request | PULL_REQUEST_RETURN_CODE |
| assignees_return_code | Return code for the assignees request | ASSIGNEES_RETURN_CODE |
| reviewers_return_code | Return code for the reviewers request | REVIEWERS_RETURN_CODE |
## Examples

View File

@@ -7,3 +7,14 @@ runs:
branding:
icon: 'activity'
color: 'yellow'
outputs:
pull_request_number:
description: 'If the pull request is opened, this is the number for it.'
pull_request_url:
description: 'If the pull request is opened, the html url for it.'
pull_request_return_code:
description: 'The pull request return code.'
assignees_return_code:
description: 'The add assignees post return code.'
reviewers_return_code:
description: 'The add reviewers post return code.'

View File

@@ -82,6 +82,14 @@ create_pull_request() {
NUMBER=$(echo "${RESPONSE}" | jq --raw-output '.number')
printf "Number opened for PR is ${NUMBER}\n"
HTML_URL=$(echo "${RESPONSE}" | jq --raw-output '.html_url')
echo ::set-env name=PULL_REQUEST_NUMBER::${NUMBER}
echo ::set-output name=pull_request_number::${NUMBER}
echo ::set-env name=PULL_REQUEST_RETURN_CODE::${RETVAL}
echo ::set-output name=pull_request_return_code::${RETVAL}
echo ::set-env name=PULL_REQUEST_URL::${HTML_URL}
echo ::set-output name=pull_request_url::${HTML_URL}
# Assignees are defined
if [[ "$ASSIGNEES" != '""' ]]; then
@@ -98,7 +106,11 @@ create_pull_request() {
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"
RETVAL=$?
printf "Add assignees return code: ${RETVAL}\n"
echo ::set-env name=ASSIGNEES_RETURN_CODE::${RETVAL}
echo ::set-output name=assignees_return_code::${RETVAL}
fi
# Reviewers or team reviewers are defined
@@ -120,7 +132,11 @@ create_pull_request() {
DATA="{\"reviewers\":[${REVIEWERS}], \"team_reviewers\":[${TEAM_REVIEWERS}]}"
echo "${DATA}"
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${REVIEWERS_URL}
printf "$?\n"
RETVAL=$?
printf "Add reviewers return code: ${RETVAL}\n"
echo ::set-env name=REVIEWERS_RETURN_CODE::${RETVAL}
echo ::set-output name=reviewers_return_code::${RETVAL}
fi
fi