-
-
Notifications
You must be signed in to change notification settings - Fork 85
90 lines (77 loc) · 3.19 KB
/
project-labelling.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Project labelling
on:
project_card:
types: [created, moved, deleted]
jobs:
process-project:
name: Add/remove the project label and set the matrix variable
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setMatrixData.outputs.matrix }}
statusLabel: ${{ steps.setStatusLabel.outputs.statusLabel }}
steps:
- name: Fetch project data
run: |
echo 'PROJECT_DATA<<EOF' >> $GITHUB_ENV
curl --request GET --url '${{ github.event.project_card.project_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
### Add or remove the project label ###
- name: Add the project label
uses: andymckay/labeler@master
if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }}
with:
add-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}"
- name: Remove the project label
uses: andymckay/labeler@master
if: ${{ contains(github.event.action, 'deleted') }}
with:
remove-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}"
### Fetch project columns ###
- name: Fetch all columns
run: |
echo 'ALL_COLUMNS_DATA<<EOF' >> $GITHUB_ENV
curl --request GET --url '${{ fromJSON(env.PROJECT_DATA).columns_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' | jq --compact-output '["Status: " + .[].name]' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Fetch column info
run: |
echo 'COLUMN_DATA<<EOF' >> $GITHUB_ENV
curl --request GET --url '${{ github.event.project_card.column_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- uses: actions/github-script@v6
id: setMatrixData
with:
result-encoding: string
script: |
const columnData = JSON.parse(process.env.COLUMN_DATA)
const allColumnsData = JSON.parse(process.env.ALL_COLUMNS_DATA)
const matrix = allColumnsData.filter((label) => {
return label !== `Status: ${columnData.name}`
});
core.setOutput('matrix', matrix)
- name: Set the status label
id: setStatusLabel
run: |
echo "statusLabel=${{ fromJSON(env.COLUMN_DATA).name }}" >> $GITHUB_OUTPUT
remove-labels:
runs-on: ubuntu-latest
needs: process-project
if: ${{ contains(github.event.action, 'deleted') || contains(github.event.action, 'moved') }}
strategy:
matrix:
label: ${{fromJson(needs.process-project.outputs.matrix)}}
steps:
- name: Remove the status label
uses: andymckay/labeler@master
with:
remove-labels: ${{ matrix.label }}
add-labels:
runs-on: ubuntu-latest
needs:
- process-project
- remove-labels
if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }}
steps:
- name: Add the status label
uses: andymckay/labeler@master
with:
add-labels: "Status: ${{ needs.process-project.outputs.statusLabel }}"