Files
PX4-Autopilot/.github/workflows/label.yml
T
Ramon Roche 3ae123f2b5 fix(ci): set GH_REPO so labeler works without checkout
The auto-label step in pull_request_target runs without a repo
checkout, so gh pr view/edit fail with 'not a git repository'.
Setting GH_REPO points gh at the right repo without needing a
checkout step.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
2026-04-28 15:39:02 -06:00

60 lines
1.7 KiB
YAML

# This workflow will triage pull requests and apply labels based on the
# PR title prefix and paths that are modified in the pull request.
# The path labels are set up in .github/labeler.yml
#
# See: https://github.com/actions/labeler
name: Labeler
on:
pull_request_target:
types: [opened, edited, synchronize, reopened, ready_for_review]
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Label PR title type
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
if [[ ! "$PR_TITLE" =~ ^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\([a-zA-Z0-9_./-]+\)!?:\ .{5,}$ ]]; then
echo "No conventional commit type detected; Commit Quality validates title format."
exit 0
fi
type="${BASH_REMATCH[1]}"
case "$type" in
feat) label="kind:feature" ;;
fix) label="kind:bug" ;;
refactor) label="kind:refactor" ;;
perf) label="kind:improvement" ;;
test) label="kind:test" ;;
docs|style|build|ci|chore|revert) label="kind:chore" ;;
esac
current_labels="$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')"
if grep -Fxq "$label" <<< "$current_labels"; then
echo "PR already has $label."
exit 0
fi
echo "Adding $label based on PR title type '$type'."
gh pr edit "$PR_NUMBER" --add-label "$label"
- uses: actions/labeler@v6
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"