|
| 1 | +# SPDX-FileCopyrightText: 2023 Alliander N.V. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Add pull requests to the overview board |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: [Prepare PR data] |
| 10 | + types: [completed] |
| 11 | + |
| 12 | +env: |
| 13 | + todo: Pending |
| 14 | + changes_requested: Changes Requested |
| 15 | + approved: Approved |
| 16 | + |
| 17 | +jobs: |
| 18 | + read-data-and-automate: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + if: github.event.workflow_run.conclusion == 'success' |
| 21 | + outputs: |
| 22 | + pr_node_id: ${{ steps.pr_node_id.outputs.content }} |
| 23 | + event_action: ${{ steps.event_action.outputs.content }} |
| 24 | + review_pr_node_id: ${{ steps.review_pr_node_id.outputs.content }} |
| 25 | + review_state: ${{ steps.review_state.outputs.content }} |
| 26 | + steps: |
| 27 | + # Data retrieval steps in case of a PR event |
| 28 | + - name: Download PR data artifact |
| 29 | + if: github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'pull_request_target' |
| 30 | + uses: dawidd6/action-download-artifact@v2 |
| 31 | + with: |
| 32 | + workflow: Prepare PR data |
| 33 | + run_id: ${{ github.event.workflow_run.id }} |
| 34 | + name: PR_DATA |
| 35 | + - name: Read PR event's PR_NODE_ID.txt |
| 36 | + if: github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'pull_request_target' |
| 37 | + id: pr_node_id |
| 38 | + uses: juliangruber/read-file-action@v1 |
| 39 | + with: |
| 40 | + path: ./PR_NODE_ID.txt |
| 41 | + trim: true |
| 42 | + - name: Read PR event's EVENT_ACTION.txt |
| 43 | + if: github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'pull_request_target' |
| 44 | + id: event_action |
| 45 | + uses: juliangruber/read-file-action@v1 |
| 46 | + with: |
| 47 | + path: ./EVENT_ACTION.txt |
| 48 | + trim: true |
| 49 | + # Data retrieval steps in case of a PR review event |
| 50 | + - name: Download PR review data artifact |
| 51 | + if: github.event.workflow_run.event == 'pull_request_review' |
| 52 | + uses: dawidd6/action-download-artifact@v2 |
| 53 | + with: |
| 54 | + workflow: Prepare PR data |
| 55 | + run_id: ${{ github.event.workflow_run.id }} |
| 56 | + name: REVIEW_DATA |
| 57 | + - name: Read PR review event's PR_NODE_ID.txt |
| 58 | + if: github.event.workflow_run.event == 'pull_request_review' |
| 59 | + id: review_pr_node_id |
| 60 | + uses: juliangruber/read-file-action@v1 |
| 61 | + with: |
| 62 | + path: ./PR_NODE_ID.txt |
| 63 | + trim: true |
| 64 | + - name: Read PR review event's REVIEW_STATE.txt |
| 65 | + if: github.event.workflow_run.event == 'pull_request_review' |
| 66 | + id: review_state |
| 67 | + uses: juliangruber/read-file-action@v1 |
| 68 | + with: |
| 69 | + path: ./REVIEW_STATE.txt |
| 70 | + trim: true |
| 71 | + # Project automation steps |
| 72 | + - name: Move PR to ${{ env.todo }} |
| 73 | + if: ((github.event.workflow_run.event == 'pull_request' || |
| 74 | + github.event.workflow_run.event == 'pull_request_target') && |
| 75 | + (steps.event_action.outputs.content == 'opened' || |
| 76 | + steps.event_action.outputs.content == 'reopened')) || |
| 77 | + (github.event.workflow_run.event == 'pull_request_review' && |
| 78 | + steps.review_state.outputs.content == 'dismissed') |
| 79 | + uses: leonsteinhaeuser/[email protected] |
| 80 | + with: |
| 81 | + project_id: 7 |
| 82 | + gh_token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }} |
| 83 | + organization: openscd |
| 84 | + resource_node_id: ${{ github.event.workflow_run.event == 'pull_request_review' && steps.review_pr_node_id.outputs.content || steps.pr_node_id.outputs.content }} |
| 85 | + status_value: ${{ env.todo }} |
| 86 | + - name: Move PR to ${{env.approved}} |
| 87 | + if: github.event.workflow_run.event == 'pull_request_review' && steps.review_state.outputs.content == 'approved' |
| 88 | + uses: leonsteinhaeuser/[email protected] |
| 89 | + with: |
| 90 | + project_id: 7 |
| 91 | + gh_token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }} |
| 92 | + organization: openscd |
| 93 | + resource_node_id: ${{ steps.review_pr_node_id.outputs.content }} |
| 94 | + status_value: ${{ env.approved }} |
| 95 | + - name: Move PR to ${{env.changes_requested}} |
| 96 | + if: github.event.workflow_run.event == 'pull_request_review' && steps.review_state.outputs.content == 'changes_requested' |
| 97 | + uses: leonsteinhaeuser/[email protected] |
| 98 | + with: |
| 99 | + project_id: 7 |
| 100 | + gh_token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }} |
| 101 | + organization: openscd |
| 102 | + resource_node_id: ${{ steps.review_pr_node_id.outputs.content }} |
| 103 | + status_value: ${{ env.changes_requested }} |
0 commit comments