Skip to content

worflow addition

worflow addition #5

Workflow file for this run

name: Auto Label PRs
on:
pull_request:
types:
- opened
- synchronize
jobs:
label-pr:
runs-on: ubuntu-latest
steps:
- name: Check for Bug, Feature, or Enhancement
id: pr-label
run: |
pr_labels=""
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
# Check for specific keywords in changed files
for file in $changed_files; do
if grep -qE 'bugfix|bug\s|fix\s|fixed\s|fixing\s|issue\s|bug\s|error\s|problem\s' $file; then
pr_labels="${pr_labels}bug,"
fi
if grep -qE 'feature|new\sfeature|feature\saddition' $file; then
pr_labels="${pr_labels}feature,"
fi
if grep -qE 'enhancement|improvement|enhance\s|improve\s' $file; then
pr_labels="${pr_labels}enhancement,"
fi
done
# Remove trailing comma and set labels
pr_labels="${pr_labels%,}"
echo "::set-output name=labels::${pr_labels}"
- name: Set PR Labels
if: steps.pr-label.outputs.labels != ''
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = "${{ steps.pr-label.outputs.labels }}".split(',');
const issue = context.issue;
// Remove existing labels to avoid duplicates
await github.issues.removeLabels({ ...issue });
// Set the new labels
await github.issues.addLabels({ ...issue, labels });