-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (69 loc) · 3.21 KB
/
severity-label-changes.yml
File metadata and controls
81 lines (69 loc) · 3.21 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
77
78
79
80
81
name: Detect and Validate Severity Label ChangesAdd commentMore actions
on:
issues:
types:
- unlabeled
permissions:
issues: write # Ensure the GITHUB_TOKEN has write permissions for issues
jobs:
label_change_bot:
runs-on: ubuntu-latest
steps:
# Step 1: Set environment variable for label name
- name: Set environment variable for label name
run: echo "GITHUB_EVENT_LABEL_NAME=${{ github.event.label.name }}" >> $GITHUB_ENV
# Step 2: Check if the label is a severity label
- name: Check if label is a severity label
id: check_label
run: |
# List of severity labels
SEVERITY_LABELS=("Severity-1" "Severity-2" "Severity-3" "Severity-4")
# Check if the label is one of the severity labels
if [[ " ${SEVERITY_LABELS[*]} " =~ " ${GITHUB_EVENT_LABEL_NAME} " ]]; then
echo "is_severity=true" >> $GITHUB_ENV
else
echo "is_severity=false" >> $GITHUB_ENV
fi
# Step 3: Validate Severity Labels After Removal
- name: Validate Severity Labels After Removal
if: ${{ github.event.action == 'unlabeled' }}
run: |
# List of severity labels
SEVERITY_LABELS=("Severity-1" "Severity-2" "Severity-3" "Severity-4")
# Get all labels currently on the issue
LABELS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"${{ github.event.issue.url }}/labels?per_page=100" | jq -r '.[].name')
no_severity=true
# Check if at least one severity label exists after the removal
for label in "${SEVERITY_LABELS[@]}"; do
if echo "$LABELS" | grep -q "^$label$"; then
no_severity=false
break
fi
done
echo "no_severity=$no_severity" >> $GITHUB_ENV
# Step 4: Tag the actor if No Severity Label Found
- name: Tag the actor if No Severity Label Found
if: env.no_severity == 'true'
run: |
# Specify the user to be tagged
USER_TO_TAG="@github/hcl-lead"
# Add a comment tagging the actor
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"body\": \"${USER_TO_TAG}, there is no severity label on this issue. Please add one to ensure proper tracking.\n\n \"}" \
"${{ github.event.issue.url }}/comments"
# Step 5: Tag @github/hcl-lead if Severity Label is Changed
- name: Tag @github/hcl-lead if Severity Label is Changed
if: env.no_severity == 'false' && env.is_severity == 'true'
run: |
# Specify the user to be tagged
USER_TO_TAG="@github/hcl-lead"
# Add a comment tagging the user
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"body\": \"@${{ github.actor }} The severity label has been updated. Please update the same in the project board.\n\n FYI ${USER_TO_TAG}.\"}" \
"${{ github.event.issue.url }}/comments"