Skip to content

Commit a737c42

Browse files
authored
chore: adds pr to overview board (openscd#1319)
splitted into 2 workflows as a workaround to account for prs from forks
1 parent e5bc0b8 commit a737c42

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Prepare PR data
6+
# Necessary step to allow adding external PRs to the project board
7+
8+
on: [pull_request, pull_request_target, pull_request_review]
9+
10+
jobs:
11+
save-pr-data:
12+
name: Save PR data to file
13+
runs-on: ubuntu-latest
14+
if: ${{ github.event.pull_request.user.login != 'github-actions[bot]' }}
15+
steps:
16+
- name: Save PR node_id and event_action to files
17+
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
18+
run: echo ${{ github.event.pull_request.node_id }} > PR_NODE_ID.txt && echo ${{ github.event.action }} > EVENT_ACTION.txt
19+
- name: Archive PR node_id and event_action
20+
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
21+
uses: actions/upload-artifact@v3
22+
with:
23+
name: PR_DATA
24+
path: |
25+
PR_NODE_ID.txt
26+
EVENT_ACTION.txt
27+
- name: Save PR node_id and review_state to files
28+
if: github.event_name == 'pull_request_review'
29+
run: echo ${{ github.event.pull_request.node_id }} > PR_NODE_ID.txt && echo ${{ github.event.review.state }} > REVIEW_STATE.txt
30+
- name: Archive PR and review_state
31+
if: github.event_name == 'pull_request_review'
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: REVIEW_DATA
35+
path: |
36+
PR_NODE_ID.txt
37+
REVIEW_STATE.txt

0 commit comments

Comments
 (0)