robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
4.2 KiB101 linesraw
1name: "label-pr"
2on:
3  pull_request_target:
4    types: [opened, synchronize, reopened, ready_for_review]
5
6permissions: {}
7
8jobs:
9  label:
10    if: github.event.action == 'opened'
11    runs-on: ubuntu-latest
12    permissions:
13      contents: read
14      pull-requests: write
15    steps:
16    - uses: actions/checkout@v7.0.1
17      with:
18        persist-credentials: false
19
20    - name: "changed-files"
21      uses: actions/labeler@v7.0.0
22      with:
23        configuration-path: .github/scripts/labeler_configuration.yml
24
25    # Scope GITHUB_TOKEN to this step only, avoid exposing to 3P `actions/labeler`.
26    - name: "guess type/scope from title"
27      env:
28        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29        GH_REPO: ${{ github.repository }}
30        PR_NUMBER: ${{ github.event.pull_request.number }}
31        PR_TITLE: ${{ github.event.pull_request.title }}
32      run: |
33        gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|([[:alpha:]]+)(\(.*\))?!?:.*|\1|')" || true
34        gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|[[:alpha:]]+\((.+)\)!?:.*|\1|')" || true
35        gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|[[:alpha:]]+(\(.*\))?!:.*|breaking-change|')" || true
36
37    - name: "target:release"
38      if: startsWith(github.base_ref, 'release')
39      uses: actions/github-script@v9
40      with:
41        script: |
42          github.rest.issues.addLabels({
43            issue_number: context.issue.number,
44            owner: context.repo.owner,
45            repo: context.repo.repo,
46            labels: ['target:release']
47          })
48
49  no-ai-advertisements:
50    runs-on: ubuntu-latest
51    permissions:
52      # Least privilege.
53      pull-requests: read
54    env:
55      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56      GH_REPO: ${{ github.repository }}
57      PR_NUMBER: ${{ github.event.pull_request.number }}
58    steps:
59    # AGENTS.md: disclose with a bare "AI-assisted" trailer, and do not name the model or service.
60    - name: "Reject AI advertisements in commit messages"
61      shell: bash
62      run: |
63        set -euo pipefail
64
65        # Prefix each message line with its commit, so a failure names the offender.
66        commits=$(gh api "repos/$GH_REPO/pulls/$PR_NUMBER/commits" --paginate \
67          --jq '.[] | .sha[0:12] as $sha | .commit.message | split("\n")[] | "\($sha) \(.)"')
68
69        tools='aider|anthropic|chatgpt|claude|cline|codex|copilot|cursor|devin|gemini|openai|opencode|windsurf|\bamp\b|\bai\b|\bllm\b|\bgpt\b'
70        by='(co-authored|signed-off|assisted|helped|generated|written|created|reviewed|suggested|reported|tested|debugged)[ -]?by'
71        hosts='claude\.ai|anthropic\.com|openai\.com|chatgpt\.com|copilot\.microsoft\.com|cursor\.(com|sh)|ampcode\.com|codeium\.com|windsurf\.com|(gemini|aistudio)\.google\.com'
72
73        found=$({
74          # Attribution trailers and phrasing.
75          grep -Ei "^\S+ +$by:.*($tools)" <<< "$commits" || true
76          grep -Ei "(generated|written|assisted|supported|powered|created|helped)[ -](by|with)[: ]+.*($tools)" <<< "$commits" || true
77          # Session links and trailers.
78          grep -Ei "^\S+ +($tools)[a-z0-9-]*-(session|thread|chat|conversation|link|url|id):" <<< "$commits" || true
79          grep -Ei "https?://[^ ]*($hosts)" <<< "$commits" || true
80          grep -Ei '@(anthropic|openai)\.com' <<< "$commits" || true
81          # Tool names anywhere, not just as attribution. Disabled to avoid false positives, for now...
82          # grep -Ei 'aider|anthropic|chatgpt|claude|codex|copilot|devin|gemini|openai|opencode|windsurf' <<< "$commits" || true
83          # The "AI-assisted" trailer must not name the tool.
84          grep -Ei '^\S+ +AI-assisted:.*\S' <<< "$commits" || true
85          grep -F '🤖' <<< "$commits" || true
86        } | sort -u)
87
88        if [[ -n "$found" ]]; then
89          echo 'Remove AI advertisements from commit messages ("Co-authored-by: Claude", etc.).'
90          echo 'Only a generic "AI-assisted" token is allowed, see AGENTS.md.'
91          echo
92          echo "$found"
93          exit 1
94        fi
95
96  request-reviewer:
97    if: github.event.action == 'opened'
98    needs: label
99    permissions:
100      pull-requests: write
101    uses: ./.github/workflows/reviewers_add.yml