-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Add github/approve-pull-request action
- Loading branch information
1 parent
3287c36
commit b185a35
Showing
3 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action | ||
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs | ||
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions | ||
# https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request | ||
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request | ||
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run | ||
|
||
name: "Approve pull request" | ||
|
||
description: "Approves a pull request" | ||
|
||
inputs: | ||
github-token: | ||
description: "GitHub token of a user with permission to approve a pull request" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
|
||
steps: | ||
- name: "Determine pull request number" | ||
uses: "actions/github-script@v5" | ||
with: | ||
github-token: "${{ inputs.github-token }}" | ||
script: | | ||
if (context.eventName == 'pull_request') { | ||
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.pull_request.number); | ||
return; | ||
} | ||
if (context.eventName == 'workflow_run') { | ||
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.workflow_run.pull_requests[0].number); | ||
return; | ||
} | ||
core.setFailed(`Unable to determine the pull request number for event "${context.eventName}"`); | ||
- name: "Approve pull request" | ||
uses: "actions/github-script@v5" | ||
with: | ||
github-token: "${{ inputs.github-token }}" | ||
script: | | ||
if (!process.env.PULL_REQUEST_NUMBER) { | ||
core.setFailed("The environment variable PULL_REQUEST_NUMBER is not defined.") | ||
return; | ||
} | ||
try { | ||
await github.rest.pulls.createReview({ | ||
event: "APPROVE", | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: process.env.PULL_REQUEST_NUMBER, | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |