Skip to content

Add PR label action

Add PR label action #2

Workflow file for this run

name: Pull Request Labels
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
jobs:
check-labels:
runs-on: ubuntu-latest
steps:
- 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
errorMessage="No labels found on PR"
else
for label in $LABELS; do
if [[ "${REQUIRED_LABELS[@]}" =~ "${label}" ]]; then
echo "Matched label $label"
echo "::set-output name=matched::true"
exit 0
fi
done
errorMessage="No matching label found"
fi
if [ -n "$errorMessage" ]; then
gh pr comment ${{ github.event.pull_request.number }} --body "## Pull Request Labels\n$errorMessage"
exit 1
fi
shell: bash