Skip to content
Merged
Show file tree
Hide file tree
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
146 changes: 122 additions & 24 deletions .github/workflows/auto-label-issue.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Auto Label Issues Based on Title
name: Auto Label Issues Based on Title and Content

on:
issues:
Expand All @@ -7,33 +7,131 @@ on:
jobs:
label-issues:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Auto-label issues based on title
- name: Auto-label issues based on title and content
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: |
ISSUE_TITLE=$(jq -r .issue.title "$GITHUB_EVENT_PATH" | tr '[:upper:]' '[:lower:]')
if [[ "$ISSUE_TITLE" == *"bug"* ]]; then
LABELS="bug"
elif [[ "$ISSUE_TITLE" == *"feature"* ]]; then
LABELS="feature"
elif [[ "$ISSUE_TITLE" == *"enhancement"* ]]; then
LABELS="enhancement"
elif [[ "$ISSUE_TITLE" == *"documentation"* ]]; then
LABELS="documentation"
else
LABELS="help wanted"
echo " Auto-labeling issue #$ISSUE_NUMBER"
echo "Title: $ISSUE_TITLE"
echo "Body: $ISSUE_BODY"

# Convert to lowercase for case-insensitive matching
TITLE_LOWER=$(echo "$ISSUE_TITLE" | tr '[:upper:]' '[:lower:]')
BODY_LOWER=$(echo "$ISSUE_BODY" | tr '[:upper:]' '[:lower:]')
COMBINED_TEXT="$TITLE_LOWER $BODY_LOWER"

# Initialize labels array
LABELS=()

# Type-based labels (mutually exclusive - use first match)
if [[ "$COMBINED_TEXT" =~ (bug|error|issue|problem|broken|fail|crash|exception) ]]; then
LABELS+=("bug")
echo " Detected: Bug"
elif [[ "$COMBINED_TEXT" =~ (feature|add|new|implement|create) ]]; then
LABELS+=("enhancement")
echo " Detected: Enhancement"
elif [[ "$COMBINED_TEXT" =~ (doc|documentation|readme|guide|tutorial) ]]; then
LABELS+=("documentation")
echo "Detected: Documentation"
elif [[ "$COMBINED_TEXT" =~ (refactor|improve|optimize|clean|restructure) ]]; then
LABELS+=("refactoring")
echo " Detected: Refactoring"
elif [[ "$COMBINED_TEXT" =~ (test|testing|spec|unit test|integration test) ]]; then
LABELS+=("testing")
echo " Detected: Testing"
fi

curl -X POST \

# Priority labels
if [[ "$COMBINED_TEXT" =~ (urgent|critical|blocker|asap|immediately) ]]; then
LABELS+=("priority: high")
echo " Detected: High Priority"
elif [[ "$COMBINED_TEXT" =~ (minor|small|trivial|nice to have|low priority) ]]; then
LABELS+=("priority: low")
echo "Detected: Low Priority"
fi

# Difficulty labels
if [[ "$COMBINED_TEXT" =~ (beginner|easy|simple|starter|first time|good first issue) ]]; then
LABELS+=("good first issue")
echo " Detected: Good First Issue"
elif [[ "$COMBINED_TEXT" =~ (complex|advanced|difficult|hard|expert) ]]; then
LABELS+=("advanced")
echo "Detected: Advanced"
fi

# Technology-specific labels
if [[ "$COMBINED_TEXT" =~ (react|jsx|tsx|component) ]]; then
LABELS+=("react")
echo " Detected: React"
fi

if [[ "$COMBINED_TEXT" =~ (typescript|ts|type|interface) ]]; then
LABELS+=("typescript")
echo "Detected: TypeScript"
fi

if [[ "$COMBINED_TEXT" =~ (css|style|styling|tailwind|design) ]]; then
LABELS+=("styling")
echo " Detected: Styling"
fi

if [[ "$COMBINED_TEXT" =~ (api|endpoint|request|response|fetch) ]]; then
LABELS+=("api")
echo "Detected: API"
fi

if [[ "$COMBINED_TEXT" =~ (performance|slow|speed|optimize|load time) ]]; then
LABELS+=("performance")
echo "⚡ Detected: Performance"
fi

if [[ "$COMBINED_TEXT" =~ (security|vulnerability|exploit|auth|permission) ]]; then
LABELS+=("security")
echo "Detected: Security"
fi

if [[ "$COMBINED_TEXT" =~ (accessibility|a11y|screen reader|aria) ]]; then
LABELS+=("accessibility")
echo "♿ Detected: Accessibility"
fi

# Default label if no specific type detected
if [ ${#LABELS[@]} -eq 0 ]; then
LABELS+=("help wanted")
echo " Default: Help Wanted"
fi

# Convert array to JSON format
LABELS_JSON=$(printf '%s\n' "${LABELS[@]}" | jq -R . | jq -s .)

echo "Applying labels: ${LABELS[*]}"

# Apply labels
RESPONSE=$(curl -s -w "%{http_code}" \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \

-H "Accept: application/vnd.github.v3+json" \

-d "{\"labels\":[\"$LABELS\"]}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.issue.number }}/labels"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d "{\"labels\":$LABELS_JSON}" \
"https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels")

HTTP_CODE="${RESPONSE: -3}"

if [ "$HTTP_CODE" = "200" ]; then
echo "Successfully applied labels to issue #$ISSUE_NUMBER"
else
echo "Failed to apply labels (HTTP $HTTP_CODE)"
echo "Response: ${RESPONSE%???}"
fi
91 changes: 91 additions & 0 deletions .github/workflows/setup-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Setup Repository Labels

on:
workflow_dispatch:
push:
branches: [main, master]
paths:
- '.github/workflows/setup-labels.yml'

jobs:
setup-labels:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read

steps:
- name: Setup Repository Labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
echo "🏷️ Setting up repository labels..."

# Define labels with their colors and descriptions
declare -A LABELS=(
["bug"]="#d73a4a|Something isn't working"
["enhancement"]="#a2eeef|New feature or request"
["documentation"]="#0075ca|Improvements or additions to documentation"
["refactoring"]="#fbca04|Code improvements and restructuring"
["testing"]="#0e8a16|Related to testing"
["priority: high"]="#d93f0b|High priority issue"
["priority: low"]="#6c757d|Low priority issue"
["good first issue"]="#7057ff|Good for newcomers"
["advanced"]="#b60205|Requires advanced knowledge"
["help wanted"]="#008672|Extra attention is needed"
["react"]="#61dafb|Related to React"
["typescript"]="#3178c6|Related to TypeScript"
["styling"]="#e99695|CSS, styling, design"
["api"]="#5319e7|API related"
["performance"]="#ff6b6b|Performance improvements"
["security"]="#ee0701|Security related"
["accessibility"]="#54473f|Accessibility improvements"
)

for label in "${!LABELS[@]}"; do
IFS='|' read -r color description <<< "${LABELS[$label]}"

echo "Creating label: $label"

# Check if label exists
EXISTING=$(curl -s \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/labels/$label" | \
jq -r '.name // "not_found"')

if [ "$EXISTING" = "not_found" ]; then
# Create new label
RESPONSE=$(curl -s -w "%{http_code}" \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d "{\"name\":\"$label\",\"color\":\"${color#\#}\",\"description\":\"$description\"}" \
"https://api.github.com/repos/$REPO/labels")

HTTP_CODE="${RESPONSE: -3}"
if [ "$HTTP_CODE" = "201" ]; then
echo "✅ Created label: $label"
else
echo "❌ Failed to create label: $label (HTTP $HTTP_CODE)"
fi
else
# Update existing label
RESPONSE=$(curl -s -w "%{http_code}" \
-X PATCH \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d "{\"color\":\"${color#\#}\",\"description\":\"$description\"}" \
"https://api.github.com/repos/$REPO/labels/$label")

HTTP_CODE="${RESPONSE: -3}"
if [ "$HTTP_CODE" = "200" ]; then
echo "🔄 Updated label: $label"
else
echo "❌ Failed to update label: $label (HTTP $HTTP_CODE)"
fi
fi
done

echo "🎉 Label setup completed!"
Loading