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