Skip to content

Commit

Permalink
Add PR label action
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed Feb 12, 2024
1 parent cf7a580 commit a1dd559
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/pr-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Pull Request Labels

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]

jobs:
check-labels:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Check for Pull Request Labels
run: |
REQUIRED_LABELS=("documentation" "bugfix" "chore" "enhancement" "ignore-for-release" "security" "sorbet")
LABELS=$(gh pr view --json labels --jq ".labels[] .name" ${{ github.event.pull_request.number }})
errorMessage=""
if [ -z "$LABELS" ]; then
echo "No labels found on PR"
errorMessage="No labels found on PR"
else
for label in $LABELS; do
if [[ "${REQUIRED_LABELS[@]}" =~ "${label}" ]]; then
echo "Matched label $label"
exit 0
fi
done
echo "No matching required labels found on PR"
errorMessage="No matching label found"
fi
if [ -n "$errorMessage" ]; then
echo "### Pull Request Labels" > comment.md
echo "" >> comment.md
echo "$errorMessage" >> comment.md
echo "" >> comment.md
echo "Please add one of the following labels to your pull request:" >> comment.md
echo "" >> comment.md
gh pr comment ${{ github.event.pull_request.number }} --body-file comment.md --edit-last
exit 1
fi
shell: bash

0 comments on commit a1dd559

Please sign in to comment.