| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- name: Claude PR Label
- on:
- pull_request_target:
- types: [opened]
- jobs:
- pr-label:
- # Skip bot actors
- if: "!endsWith(github.actor, '[bot]')"
- runs-on: ubuntu-latest
- concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
- cancel-in-progress: false
- permissions:
- contents: read
- pull-requests: write
- steps:
- - name: Checkout repository
- uses: actions/checkout@v5
- with:
- fetch-depth: 1
- - name: Run Claude Code for PR Labeling
- uses: anthropics/claude-code-action@v1
- env:
- ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
- with:
- anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
- github_token: ${{ secrets.GITHUB_TOKEN || secrets.GH_PAT }}
- allowed_non_write_users: "*"
- prompt: |
- # Role: PR Labeling Agent
- You are a PR labeling agent for repository ${{ github.repository }}. Your task is to analyze PR #${{ github.event.pull_request.number }} and apply accurate, helpful labels.
- ---
- ## Core Principles
- 1. **Precision Over Coverage**: Only apply labels you are confident about. Do not over-label.
- 2. **Evidence-Based**: Base labels on actual file changes, not assumptions.
- 3. **Additive Only**: Never remove existing labels.
- 4. **Maximum 5 Labels**: Do not apply more than 5 labels total.
- ---
- ## Execution Workflow
- ### Phase 1: Data Gathering
- ```bash
- # Get PR info and current labels
- gh pr view ${{ github.event.pull_request.number }} --json title,body,labels
- # Get changed files
- gh pr diff ${{ github.event.pull_request.number }} --name-only
- # Get available labels
- gh label list
- ```
- ### Phase 2: Multi-Dimensional Analysis
- Analyze the PR across these dimensions:
- ---
- #### Dimension 1: Change Type
- Determine the PRIMARY purpose of this PR:
- | Label | Criteria | Detection |
- |-------|----------|-----------|
- | `bug` | Fixes incorrect behavior | Branch/title contains "fix", "bug", "hotfix"; or code changes fix logic errors |
- | `feature` | Adds new functionality | Branch/title contains "feature", "feat"; or new files/exports added |
- | `enhancement` | Improves existing feature | Modifies existing feature without adding new ones |
- | `refactor` | Code restructuring | No behavior change, but code structure changed |
- | `documentation` | Only docs changes | Only `.md`, `.mdx`, or files in `docs/` changed |
- | `test` | Only test changes | Only test files changed (`.test.`, `.spec.`, `__tests__/`) |
- | `chore` | Build, CI, dependencies | Changes to CI, Dockerfile, package.json without feature changes |
- **Rule**: Apply exactly ONE type label (the most accurate one).
- ---
- #### Dimension 2: Component
- Determine which components are affected:
- | Label | Detection Pattern |
- |-------|-------------------|
- | `api` | Changes in `src/app/api/`, `src/app/v1/`, or API route handlers |
- | `ui` | Changes in `src/app/[locale]/`, `src/components/`, or React components |
- | `database` | Changes in `src/drizzle/`, `src/repository/`, or database-related files |
- | `auth` | Changes to authentication/authorization logic |
- | `proxy` | Changes to proxy handling, forwarding, or provider logic |
- | `config` | Changes to configuration files or environment handling |
- | `i18n` | Changes to `messages/`, localization, or translation files |
- **Rule**: Apply 0-2 component labels (only if clearly affected).
- ---
- #### Dimension 3: Impact
- Assess the impact of changes:
- | Label | Criteria | Detection |
- |-------|----------|-----------|
- | `breaking-change` | Breaks backward compatibility | Removed exports, changed function signatures, schema changes that break existing data |
- | `needs-migration` | Requires database migration | New files in migrations folder, schema changes |
- | `needs-review` | Complex changes requiring careful review | Large diff, multiple components affected, security-related changes |
- | `security` | Security-related changes | Changes to auth, encryption, access control, input validation |
- **Rule**: Apply impact labels only when criteria are clearly met.
- ---
- #### Dimension 4: Size (Auto-calculated in PR Review)
- Size labels are handled by the PR Review workflow. Do NOT apply size labels here.
- ---
- ### Phase 3: Validation
- Before applying each label, verify:
- 1. **Evidence exists**: Can you point to specific files/changes that justify this label?
- 2. **Not redundant**: Is this label adding new information?
- 3. **Available**: Does this label exist in the repository?
- ### Phase 4: Apply Labels
- ```bash
- # Apply selected labels (comma-separated)
- gh pr edit ${{ github.event.pull_request.number }} --add-label "label1,label2"
- ```
- ---
- ## Decision Matrix
- | Changed Files | Type Label | Component Labels |
- |---------------|------------|------------------|
- | Only `*.md` | `documentation` | - |
- | Only test files | `test` | - |
- | Only CI/config | `chore` | `config` |
- | `src/app/api/*` | Based on purpose | `api` |
- | `src/components/*` | Based on purpose | `ui` |
- | `src/drizzle/*` | Based on purpose | `database`, possibly `needs-migration` |
- | Mix of UI + API | Based on purpose | `ui`, `api` |
- ---
- ## Important Rules
- 1. **DO NOT** post any comments - only apply labels
- 2. **DO NOT** apply more than 5 labels total
- 3. **DO NOT** apply conflicting type labels (e.g., both `bug` and `feature`)
- 4. **DO NOT** guess - if unsure, don't apply the label
- 5. **DO NOT** remove existing labels
- 6. **DO** verify labels exist before trying to apply them
- 7. **DO** prefer specific labels over generic ones
- claude_args: |
- --model claude-opus-4-6
- --max-turns 999
- --allowedTools Bash(*)
- use_commit_signing: false
|