-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Process Issue Open/Edit | ||
|
||
on: | ||
issues: | ||
types: | ||
- opened | ||
- edited | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
issues: write | ||
|
||
jobs: | ||
validate: | ||
name: Validate Reservation | ||
runs-on: ubuntu-latest | ||
|
||
if: | | ||
contains(github.event.issue.labels.*.name, 'reservation') | ||
steps: | ||
- name: Get GitHub App Token | ||
id: token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.ISSUEOPS_APP_ID }} | ||
private-key: ${{ secrets.ISSUEOPS_APP_PRIVATE_KEY }} | ||
owner: ${{ github.repository_owner }} | ||
|
||
# Remove the validated label. This will be re-added if validation passes. | ||
- name: Remove Validated Label | ||
id: remove-label | ||
uses: issue-ops/labeler@v2 | ||
with: | ||
action: remove | ||
github_token: ${{ steps.token.outputs.token }} | ||
labels: | | ||
validated | ||
issue_number: ${{ github.event.issue.number }} | ||
repository: ${{ github.repository }} | ||
|
||
# Parse the issue body into machine-readable JSON, so that it can be | ||
# processed by the rest of the workflow. | ||
- name: Parse Issue body | ||
id: parse | ||
uses: issue-ops/parser@v4 | ||
with: | ||
body: ${{ github.event.issue.body }} | ||
issue-form-template: reservation.yml | ||
workspace: ${{ github.workspace }} | ||
|
||
# Validate early, and validate often! Validation should be run any time an | ||
# issue is interacted with, to ensure that any changes to the issue body | ||
# are valid. | ||
- name: Validate Reservation Request | ||
id: validate | ||
uses: issue-ops/validator@v3 | ||
with: | ||
add-comment: false | ||
github-token: ${{ steps.token.outputs.token }} | ||
issue-form-template: reservation.yml | ||
issue-number: ${{ github.event.issue.number }} | ||
parsed-issue-body: ${{ steps.parse.outputs.json }} | ||
workspace: ${{ github.workspace }} | ||
|
||
# If validation passed, add the validated label to the issue. | ||
- if: ${{ steps.validate.outputs.result == 'success' }} | ||
name: Add Validated Label | ||
id: add-label | ||
uses: issue-ops/labeler@v2 | ||
with: | ||
action: add | ||
github_token: ${{ steps.token.outputs.token }} | ||
labels: | | ||
validated | ||
issue_number: ${{ github.event.issue.number }} | ||
repository: ${{ github.repository }} | ||
|
||
# If validation failed, add a comment to the issue explaining the failure. | ||
- if: ${{ steps.validate.outputs.result == 'failure' }} | ||
name: Add Validation Failure Comment | ||
id: add-failure-comment | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `:sob: Something went wrong validating your request. Please edit the issue body or close this issue and submit a new one. | ||
The following validation errors occurred: | ||
${{ steps.validate.outputs.errors }}` | ||
}) |