Skip to content

Commit 8663551

Browse files
committed
ci: add /kind, /area, /milestone label sync for issues
Mirrors pr-kind-label.yaml so directive based labeling works on issues just like PRs. prow-github.yml is still the only thing handling these commands on issues. Removing it (a separate change) would otherwise regress issue triage. Body only trigger for now and no issue_comment handling. There is therefore no new comment triggered attack surface. Ref: #956 Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
1 parent ae91966 commit 8663551

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Apply kind/area labels and milestone from issue body
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
kind-labels:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
steps:
13+
- name: Sync kind labels
14+
env:
15+
GH_TOKEN: ${{ github.token }}
16+
ISSUE_BODY: ${{ github.event.issue.body }}
17+
ISSUE_NUMBER: ${{ github.event.issue.number }}
18+
REPO: ${{ github.repository }}
19+
run: |
20+
# Remove existing kind/* labels
21+
gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json labels \
22+
-q '.labels[].name | select(startswith("kind/"))' | \
23+
while IFS= read -r label; do
24+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-label "$label" || echo "::warning::Failed to remove label '$label'"
25+
done
26+
27+
# Extract /kind values from issue body and apply labels
28+
printf '%s' "$ISSUE_BODY" | tr -d '\r' | sed -n 's|^/kind[[:space:]][[:space:]]*||p' | sed 's|[[:space:]]*$||' | sort -u | \
29+
while IFS= read -r kind; do
30+
[ -z "$kind" ] && continue
31+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --add-label "kind/$kind" || \
32+
echo "::warning::Label 'kind/$kind' not found in repository"
33+
done
34+
35+
- name: Set area labels
36+
env:
37+
GH_TOKEN: ${{ github.token }}
38+
ISSUE_BODY: ${{ github.event.issue.body }}
39+
ISSUE_NUMBER: ${{ github.event.issue.number }}
40+
REPO: ${{ github.repository }}
41+
run: |
42+
# Absence of a directive is a no-op. Area labels are also set by
43+
# maintainers through the UI and clearing here would wipe those.
44+
areas=$(printf '%s' "$ISSUE_BODY" | tr -d '\r' | sed -n 's|^/area[[:space:]][[:space:]]*||p' | \
45+
sed 's|[[:space:]]*$||' | sed '/^$/d' | sort -u)
46+
[ -z "$areas" ] && exit 0
47+
48+
# Remove existing area/* labels
49+
gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json labels \
50+
-q '.labels[].name | select(startswith("area/"))' | \
51+
while IFS= read -r label; do
52+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-label "$label" || echo "::warning::Failed to remove label '$label'"
53+
done
54+
55+
printf '%s\n' "$areas" | \
56+
while IFS= read -r area; do
57+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --add-label "area/$area" || \
58+
echo "::warning::Label 'area/$area' not found in repository"
59+
done
60+
61+
- name: Set milestone
62+
env:
63+
GH_TOKEN: ${{ github.token }}
64+
ISSUE_BODY: ${{ github.event.issue.body }}
65+
ISSUE_NUMBER: ${{ github.event.issue.number }}
66+
REPO: ${{ github.repository }}
67+
run: |
68+
# Use the last /milestone directive in the issue body
69+
milestone=$(printf '%s' "$ISSUE_BODY" | tr -d '\r' | sed -n 's|^/milestone[[:space:]][[:space:]]*||p' | \
70+
sed 's|[[:space:]]*$||' | sed '/^$/d' | tail -n 1)
71+
[ -z "$milestone" ] && exit 0
72+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --milestone "$milestone" || \
73+
echo "::warning::Milestone '$milestone' not found in repository"

0 commit comments

Comments
 (0)