Skip to content

Commit 9563355

Browse files
committed
ci: Add /area and /milestone commands to PR label sync
Extends the existing /kind label sync workflow to also handle /area and /milestone directives in the PR body. This commit uses the same gh CLI pattern as other steps in the workflow. This provides a a native GitHub replacement for the /area and /milestone commands that prow currently provides. Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
1 parent feafdf4 commit 9563355

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

.github/workflows/pr-kind-label.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Apply kind labels from PR body
1+
name: Apply kind/area labels and milestone from PR body
22

33
on:
44
pull_request_target:
@@ -34,3 +34,40 @@ jobs:
3434
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "kind/$kind" || \
3535
echo "::warning::Label 'kind/$kind' not found in repository"
3636
done
37+
38+
- name: Sync area labels
39+
env:
40+
GH_TOKEN: ${{ github.token }}
41+
PR_BODY: ${{ github.event.pull_request.body }}
42+
PR_NUMBER: ${{ github.event.pull_request.number }}
43+
REPO: ${{ github.repository }}
44+
run: |
45+
# Remove existing area/* labels
46+
gh pr view "$PR_NUMBER" --repo "$REPO" --json labels \
47+
-q '.labels[].name | select(startswith("area/"))' | \
48+
while IFS= read -r label; do
49+
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label"
50+
done
51+
52+
# Extract /area values from PR body and apply labels
53+
printf '%s' "$PR_BODY" | tr -d '\r' | grep '^/area ' | \
54+
sed 's|^/area ||' | sort -u | \
55+
while IFS= read -r area; do
56+
[ -z "$area" ] && continue
57+
gh pr edit "$PR_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+
PR_BODY: ${{ github.event.pull_request.body }}
65+
PR_NUMBER: ${{ github.event.pull_request.number }}
66+
REPO: ${{ github.repository }}
67+
run: |
68+
# Use the last /milestone directive in the PR body
69+
milestone=$(printf '%s' "$PR_BODY" | tr -d '\r' | grep '^/milestone ' | \
70+
sed 's|^/milestone ||' | tail -n 1)
71+
[ -z "$milestone" ] && exit 0
72+
gh pr edit "$PR_NUMBER" --repo "$REPO" --milestone "$milestone" || \
73+
echo "::warning::Milestone '$milestone' not found in repository"

0 commit comments

Comments
 (0)