summaryrefslogtreecommitdiffstatshomepage
path: root/.github/workflows/labeler_pr.yml
blob: 841a846460110b4228f6d7850a36db5a4427c3d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: "labeler: PR"
on:
  pull_request_target:
    types: [opened, synchronize, reopened, ready_for_review]

permissions: {}

jobs:
  changed-files:
    if: github.event.action == 'opened'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
    - uses: actions/checkout@v6
      with:
        persist-credentials: false

    - uses: actions/labeler@v6
      with:
        configuration-path: .github/scripts/labeler_configuration.yml

  type-scope:
    if: github.event.action == 'opened'
    needs: changed-files
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GH_REPO: ${{ github.repository }}
      PR_NUMBER: ${{ github.event.pull_request.number }}
      PR_TITLE: ${{ github.event.pull_request.title }}
    steps:
    - name: "Extract commit type and add as label"
      run: gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|([[:alpha:]]+)(\(.*\))?!?:.*|\1|')" || true
    - name: "Extract commit scope and add as label"
      run: gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|[[:alpha:]]+\((.+)\)!?:.*|\1|')" || true
    - name: "Extract if the PR is a breaking change and add it as label"
      run: gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|[[:alpha:]]+(\(.*\))?!:.*|breaking-change|')" || true

  ai-assisted:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GH_REPO: ${{ github.repository }}
      PR_NUMBER: ${{ github.event.pull_request.number }}
      AI_LABEL: 'AI assisted 🤖'
    steps:
    - name: "Label PRs with disclosed AI-assisted commits"
      shell: bash
      run: |
        set -euo pipefail

        commit_messages=$(gh api "repos/$GH_REPO/pulls/$PR_NUMBER/commits" --paginate --jq '.[].commit.message')

        has_ai_disclosure=false
        for pattern in \
          '^(AI|LLM|GPT)([ -][A-Za-z-]+)?: *.+' \
          'supported +by +AI' \
          '^Co-authored(-| +)by: .*(Claude|Codex|Copilot|Cursor|Gemini|Aider|Cline|Windsurf|OpenAI|OpenCode|Amp|Anthropic|GPT)'; do
          if grep -Eiq "$pattern" <<< "$commit_messages"; then
            has_ai_disclosure=true
            break
          fi
        done

        if [[ "$has_ai_disclosure" == false ]]; then
          # No supported AI disclosure found in commits
          exit 0
        fi

        pr_labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
        if grep -Fxq "$AI_LABEL" <<< "$pr_labels"; then
          # Already has label
          exit 0
        fi

        gh pr edit "$PR_NUMBER" --add-label "$AI_LABEL"

  target-release:
    if: github.event.action == 'opened'
    needs: ["changed-files", "type-scope"]
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
    - if: startsWith(github.base_ref, 'release')
      uses: actions/github-script@v9
      with:
        script: |
          github.rest.issues.addLabels({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            labels: ['target:release']
          })

  request-reviewer:
    if: github.event.action == 'opened'
    needs: ["changed-files", "type-scope", "target-release"]
    permissions:
      pull-requests: write
    uses: ./.github/workflows/reviewers_add.yml