Skip to content

Commit 3798492

Browse files
infra: add label-to-project-field mapping in add-to-project workflow
Maps solution/*, priority/*, and type/* labels to project board Solution, Priority, and Category fields automatically. Closes #13
1 parent f6c6ef1 commit 3798492

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Add to Project
2+
3+
on:
4+
issues:
5+
types: [opened, labeled]
6+
pull_request:
7+
types: [opened, labeled]
8+
9+
jobs:
10+
add-to-project:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/add-to-project@v1.0.2
14+
id: add
15+
with:
16+
project-url: https://github.com/orgs/AzureLocal/projects/3
17+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
18+
19+
set-fields:
20+
needs: add-to-project
21+
runs-on: ubuntu-latest
22+
if: github.event_name == 'issues'
23+
env:
24+
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
25+
PROJECT_ID: "PVT_kwDOCxeiOM4BR2KZ"
26+
SOLUTION_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXuY"
27+
PRIORITY_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXvs"
28+
CATEGORY_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXxA"
29+
steps:
30+
- name: Get project item ID
31+
id: find-item
32+
run: |
33+
ITEM_ID=$(gh project item-list 3 --owner AzureLocal --format json --limit 200 \
34+
| jq -r --arg url "${{ github.event.issue.html_url }}" \
35+
'.items[] | select(.content.url == $url) | .id')
36+
echo "item_id=$ITEM_ID" >> "$GITHUB_OUTPUT"
37+
38+
- name: Set Solution field
39+
if: steps.find-item.outputs.item_id != ''
40+
run: |
41+
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
42+
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
43+
OPTION_ID=""
44+
if echo "$LABELS" | grep -q '"solution/sofs"'; then
45+
OPTION_ID="1695a3e2"
46+
elif echo "$LABELS" | grep -q '"solution/avd"'; then
47+
OPTION_ID="1d1bf6c0"
48+
elif echo "$LABELS" | grep -q '"solution/loadtools"'; then
49+
OPTION_ID="bb2d53f9"
50+
elif echo "$LABELS" | grep -q '"solution/vmconvert"'; then
51+
OPTION_ID="942759d7"
52+
elif echo "$LABELS" | grep -q '"solution/docs-site"'; then
53+
OPTION_ID="75fa7361"
54+
elif echo "$LABELS" | grep -q '"solution/workspace"'; then
55+
OPTION_ID="d60c979e"
56+
fi
57+
if [ -n "$OPTION_ID" ]; then
58+
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
59+
--field-id "$SOLUTION_FIELD" --single-select-option-id "$OPTION_ID"
60+
fi
61+
62+
- name: Set Priority field
63+
if: steps.find-item.outputs.item_id != ''
64+
run: |
65+
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
66+
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
67+
OPTION_ID=""
68+
if echo "$LABELS" | grep -q '"priority/critical"'; then
69+
OPTION_ID="74334e8d"
70+
elif echo "$LABELS" | grep -q '"priority/high"'; then
71+
OPTION_ID="2e3ede9d"
72+
elif echo "$LABELS" | grep -q '"priority/medium"'; then
73+
OPTION_ID="7709e85d"
74+
elif echo "$LABELS" | grep -q '"priority/low"'; then
75+
OPTION_ID="2182b5f9"
76+
fi
77+
if [ -n "$OPTION_ID" ]; then
78+
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
79+
--field-id "$PRIORITY_FIELD" --single-select-option-id "$OPTION_ID"
80+
fi
81+
82+
- name: Set Category field
83+
if: steps.find-item.outputs.item_id != ''
84+
run: |
85+
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
86+
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
87+
OPTION_ID=""
88+
if echo "$LABELS" | grep -q '"type/feature"'; then
89+
OPTION_ID="7a4fa8ea"
90+
elif echo "$LABELS" | grep -q '"type/bug"'; then
91+
OPTION_ID="206e624a"
92+
elif echo "$LABELS" | grep -q '"type/docs"'; then
93+
OPTION_ID="355ce6c1"
94+
elif echo "$LABELS" | grep -q '"type/infra"'; then
95+
OPTION_ID="05996f93"
96+
elif echo "$LABELS" | grep -q '"type/refactor"'; then
97+
OPTION_ID="7f5509ab"
98+
elif echo "$LABELS" | grep -q '"type/security"'; then
99+
OPTION_ID="d2af4749"
100+
fi
101+
if [ -n "$OPTION_ID" ]; then
102+
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
103+
--field-id "$CATEGORY_FIELD" --single-select-option-id "$OPTION_ID"
104+
fi

0 commit comments

Comments
 (0)