Skip to content

Commit 3f5dc96

Browse files
authored
Github action for assigning area label to issues (#82)
1 parent e63eb8f commit 3f5dc96

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

.github/workflows/sync-labels-milestone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
- name: Authenticate GH CLI
1818
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
1919

20-
- name: Run Add Labels Script
20+
- name: Add Labels Script
2121
run: scripts/create-area-labels.sh
2222
env:
2323
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
2424

25-
- name: Run Add Milestone Script
25+
- name: Add Milestone Script
2626
run: scripts/create-milestone.sh
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

.github/workflows/sync-roadmap.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ jobs:
1717
- name: Authenticate GH CLI
1818
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
1919

20-
- name: Run Add Issues to Roadmap Project Script
20+
- name: Add Issues to Roadmap Project Script
2121
run: scripts/add-issues-to-project.sh
2222
env:
2323
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
2424

25+
- name: Assign Area Labels to Issues Script
26+
run: scripts/assign-area-labels-to-issues.sh all
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
29+
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
CATEGORY="${1:-}"
6+
ORG="ironcore-dev"
7+
MAX_JOBS="${MAX_JOBS:-5}" # Can override with env: MAX_JOBS=10 ./script.sh all
8+
9+
# Define categories and labels
10+
CATEGORIES="metal-automation networking storage compute iaas operatingsystem gardener-extension"
11+
LABELS="area/metal-automation area/networking area/storage area/compute area/iaas area/operatingsystem area/gardener-extension"
12+
13+
metal_automation_repos="metal-operator cloud-provider-metal cluster-api-provider-ironcore-metal ironcore-image FeDHCP boot-operator ipam metal-token-rotate metal-load-balancer-controller os-images maintenance-operator firmware-operator"
14+
networking_repos="metalnet dpservice ironcore-net ebpf-nat64 metalbond"
15+
storage_repos="ceph-provider ironcore-csi-driver"
16+
compute_repos="libvirt-provider cloud-hypervisor-provider"
17+
iaas_repos="ironcore openapi-extractor controller-utils cloud-provider-ironcore vgopath kubectl-ironcore ironcore-in-a-box provider-utils ironcore-csi-driver"
18+
operatingsystem_repos="FeOS feos-demo feos-provider"
19+
gardener_extension_repos="gardener-extension-provider-ironcore machine-controller-manager-provider-ironcore-metal gardener-extension-provider-ironcore-metal machine-controller-manager-provider-ironcore machine-controller-manager gardener-extension-os-gardenlinux"
20+
21+
run_limited_parallel() {
22+
local max_jobs=$1
23+
shift
24+
local cmds=("$@")
25+
local pids=()
26+
27+
for cmd in "${cmds[@]}"; do
28+
eval "$cmd" &
29+
pids+=($!)
30+
31+
while (( $(jobs -r | wc -l) >= max_jobs )); do
32+
sleep 0.5
33+
done
34+
done
35+
36+
wait "${pids[@]}"
37+
}
38+
39+
process_category() {
40+
local category="$1"
41+
local label
42+
local repos_var
43+
local repos
44+
local cmds=()
45+
46+
# Find label
47+
i=1
48+
for cat in $CATEGORIES; do
49+
if [[ "$cat" == "$category" ]]; then
50+
label=$(echo "$LABELS" | cut -d' ' -f"$i")
51+
break
52+
fi
53+
i=$((i+1))
54+
done
55+
56+
if [[ -z "${label:-}" ]]; then
57+
echo "❌ Unknown category '$category'"
58+
return
59+
fi
60+
61+
repos_var="${category//-/_}_repos"
62+
repos="${!repos_var}"
63+
64+
echo "✅ Category: $category"
65+
echo "🏷️ Label to apply: $label"
66+
echo "📦 Repos: $repos"
67+
echo
68+
69+
for repo in $repos; do
70+
full_repo="$ORG/$repo"
71+
cmds+=("process_repo '$full_repo' '$label'")
72+
done
73+
74+
run_limited_parallel "$MAX_JOBS" "${cmds[@]}"
75+
}
76+
77+
process_repo() {
78+
local full_repo="$1"
79+
local label="$2"
80+
81+
echo "🔍 Processing repo: $full_repo"
82+
83+
ISSUES=$(gh issue list -R "$full_repo" --state all --limit 1500 --json number,labels \
84+
--jq '.[] | [.number, (.labels | map(.name) | join(","))] | @tsv' || true)
85+
86+
if [[ -z "$ISSUES" ]]; then
87+
echo " ⚠️ No issues found in $full_repo"
88+
return
89+
fi
90+
91+
while IFS=$'\t' read -r issue_number existing_labels; do
92+
if [[ ",$existing_labels," == *",$label,"* ]]; then
93+
echo " ⚠️ Issue #$issue_number already has label '$label', skipping."
94+
else
95+
echo " ➕ Adding label '$label' to issue #$issue_number"
96+
gh issue edit "$issue_number" -R "$full_repo" --add-label "$label" || echo " ❌ Failed to label #$issue_number"
97+
fi
98+
done <<< "$ISSUES"
99+
}
100+
101+
# Handle "all" case
102+
if [[ "$CATEGORY" == "all" ]]; then
103+
for cat in $CATEGORIES; do
104+
process_category "$cat"
105+
done
106+
else
107+
process_category "$CATEGORY"
108+
fi
109+
110+
echo "🎉 Labeling complete."

0 commit comments

Comments
 (0)