1- name : Apply kind labels from PR body
1+ name : Apply kind/area labels and milestone from PR body
22
33on :
44 pull_request_target :
@@ -23,14 +23,53 @@ jobs:
2323 gh pr view "$PR_NUMBER" --repo "$REPO" --json labels \
2424 -q '.labels[].name | select(startswith("kind/"))' | \
2525 while IFS= read -r label; do
26- gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label"
26+ gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label" || echo "::warning::Failed to remove label '$label'"
2727 done
2828
2929 # Extract /kind values from PR body and apply labels
30- printf '%s' "$PR_BODY" | tr -d '\r' | grep '^/kind ' | \
31- sed 's|^/kind ||' | sort -u | \
30+ printf '%s' "$PR_BODY" | tr -d '\r' | sed -n 's|^/kind[[:space:]][[:space:]]*||p' | sed 's|[[:space:]]*$||' | sort -u | \
3231 while IFS= read -r kind; do
3332 [ -z "$kind" ] && continue
3433 gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "kind/$kind" || \
3534 echo "::warning::Label 'kind/$kind' not found in repository"
3635 done
36+
37+ - name : Set area labels
38+ env :
39+ GH_TOKEN : ${{ github.token }}
40+ PR_BODY : ${{ github.event.pull_request.body }}
41+ PR_NUMBER : ${{ github.event.pull_request.number }}
42+ REPO : ${{ github.repository }}
43+ run : |
44+ # Absence of a directive is a no-op. Area labels are also set by the
45+ # /area comment command and clearing here would wipe those.
46+ areas=$(printf '%s' "$PR_BODY" | tr -d '\r' | sed -n 's|^/area[[:space:]][[:space:]]*||p' | \
47+ sed 's|[[:space:]]*$||' | sed '/^$/d' | sort -u)
48+ [ -z "$areas" ] && exit 0
49+
50+ # Remove existing area/* labels
51+ gh pr view "$PR_NUMBER" --repo "$REPO" --json labels \
52+ -q '.labels[].name | select(startswith("area/"))' | \
53+ while IFS= read -r label; do
54+ gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label" || echo "::warning::Failed to remove label '$label'"
55+ done
56+
57+ printf '%s\n' "$areas" | \
58+ while IFS= read -r area; do
59+ gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "area/$area" || \
60+ echo "::warning::Label 'area/$area' not found in repository"
61+ done
62+
63+ - name : Set milestone
64+ env :
65+ GH_TOKEN : ${{ github.token }}
66+ PR_BODY : ${{ github.event.pull_request.body }}
67+ PR_NUMBER : ${{ github.event.pull_request.number }}
68+ REPO : ${{ github.repository }}
69+ run : |
70+ # Use the last /milestone directive in the PR body
71+ milestone=$(printf '%s' "$PR_BODY" | tr -d '\r' | sed -n 's|^/milestone[[:space:]][[:space:]]*||p' | \
72+ sed 's|[[:space:]]*$||' | sed '/^$/d' | tail -n 1)
73+ [ -z "$milestone" ] && exit 0
74+ gh pr edit "$PR_NUMBER" --repo "$REPO" --milestone "$milestone" || \
75+ echo "::warning::Milestone '$milestone' not found in repository"
0 commit comments