Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github /workflows/auto-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: "Auto Create & Assign Labels"

on:
issues:
types: [opened]
pull_request:
types: [opened]

permissions:
issues: write
pull-requests: write

jobs:
auto-label:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create labels if missing and assign
run: |
#!/bin/bash
set -e

# Determine if it's issue or PR
if [ "${{ github.event_name }}" == "issues" ]; then
ISSUE_NUMBER=${{ github.event.issue.number }}
TITLE="${{ github.event.issue.title }}"
BODY="${{ github.event.issue.body }}"
CREATOR="${{ github.event.issue.user.login }}"
else
ISSUE_NUMBER=${{ github.event.pull_request.number }}
TITLE="${{ github.event.pull_request.title }}"
BODY="${{ github.event.pull_request.body }}"
CREATOR="${{ github.event.pull_request.user.login }}"
fi

echo "Number: $ISSUE_NUMBER"
echo "Title: $TITLE"
echo "Creator: $CREATOR"

# Define labels and colors
declare -A labels
labels["Level 1 / Beginner"]="#7AE7FF"
labels["Level 2 / Intermediate"]="#FFAB70"
labels["Level 3 / Advanced"]="#FF7F7F"
labels["GSSoC 25"]="#6F42C1"

# Create labels if missing
for label in "${!labels[@]}"; do
response=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/labels \
-d "{\"name\":\"$label\",\"color\":\"${labels[$label]}\"}")
if [[ "$response" == "422" ]]; then
echo "Label '$label' already exists."
else
echo "Label '$label' created."
fi
done

sleep 2 # Ensure labels are registered

# Determine complexity label
LEVEL_LABEL="Level 3 / Advanced"
if echo "$TITLE$BODY" | grep -iqE "typo|doc|readme|ui"; then
LEVEL_LABEL="Level 1 / Beginner"
elif echo "$TITLE$BODY" | grep -iqE "feature|bug|small"; then
LEVEL_LABEL="Level 2 / Intermediate"
fi

echo "Level label: $LEVEL_LABEL"

# Assign labels and creator
ASSIGN_RESPONSE=$(curl -s -w "%{http_code}" -o /dev/null \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/$ISSUE_NUMBER \
-d "{\"labels\":[\"GSSoC 25\",\"$LEVEL_LABEL\"],\"assignees\":[\"$CREATOR\"]}")

if [[ "$ASSIGN_RESPONSE" == "200" ]]; then
echo "Labels and assignee successfully assigned: GSSoC 25, $LEVEL_LABEL"
else
echo "Failed to assign labels or assignee. Response code: $ASSIGN_RESPONSE"
fi