From 894abf7ed702bf61557628f6a48b1b95317f1538 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 10 Jan 2025 13:07:18 -0500 Subject: [PATCH] Add initial issue open workflow --- .github/workflows/process-issue.yml | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/process-issue.yml diff --git a/.github/workflows/process-issue.yml b/.github/workflows/process-issue.yml new file mode 100644 index 0000000..131ade7 --- /dev/null +++ b/.github/workflows/process-issue.yml @@ -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 }}` + })