Skip to content

Test 1

Test 1 #2

name: Detect and Validate Severity Label Changes
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')
# Check if at least one severity label exists after the removal
for label in "${SEVERITY_LABELS[@]}"; do
if [[ " $LABELS " =~ " $label " ]]; then
echo "A severity label is still present."
echo "no_severity=false" >> $GITHUB_ENV
exit 0
fi
done
# If no severity label is found, set the environment variable
echo "no_severity=true" >> $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"