|
| 1 | +# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +name: Labeling |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, reopened, synchronize] |
| 9 | + issues: |
| 10 | + types: [opened] |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + label-by-files: |
| 17 | + if: github.event_name == 'pull_request' |
| 18 | + name: Label by changed files |
| 19 | + |
| 20 | + runs-on: ubuntu-latest-low |
| 21 | + |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + pull-requests: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Apply labels based on changed files |
| 28 | + uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5 |
| 29 | + with: |
| 30 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + sync-labels: false |
| 32 | + |
| 33 | + triage-pr: |
| 34 | + needs: [label-by-files] |
| 35 | + if: > |
| 36 | + always() && |
| 37 | + github.event_name == 'pull_request' && |
| 38 | + (github.event.action == 'opened' || github.event.action == 'reopened') |
| 39 | + name: Apply default PR triage label |
| 40 | + |
| 41 | + runs-on: ubuntu-latest-low |
| 42 | + |
| 43 | + permissions: |
| 44 | + pull-requests: write |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Add '3. to review' if no triage label is set |
| 48 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 49 | + with: |
| 50 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + script: | |
| 52 | + const triageLabels = ['0. Needs triage', '1. to develop', '2. developing', '3. to review', '4. to release'] |
| 53 | + const currentLabels = context.payload.pull_request.labels.map(l => l.name) |
| 54 | + if (!triageLabels.some(l => currentLabels.includes(l))) { |
| 55 | + await github.rest.issues.addLabels({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + issue_number: context.payload.pull_request.number, |
| 59 | + labels: ['3. to review'], |
| 60 | + }) |
| 61 | + } |
| 62 | +
|
| 63 | + triage-issue: |
| 64 | + if: github.event_name == 'issues' |
| 65 | + name: Apply default issue triage label |
| 66 | + |
| 67 | + runs-on: ubuntu-latest-low |
| 68 | + |
| 69 | + permissions: |
| 70 | + issues: write |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Add '0. Needs triage' if no triage label is set |
| 74 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 75 | + with: |
| 76 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + script: | |
| 78 | + const triageLabels = ['0. Needs triage', '1. to develop', '2. developing', '3. to review', '4. to release'] |
| 79 | + const currentLabels = context.payload.issue.labels.map(l => l.name) |
| 80 | + if (!triageLabels.some(l => currentLabels.includes(l))) { |
| 81 | + await github.rest.issues.addLabels({ |
| 82 | + owner: context.repo.owner, |
| 83 | + repo: context.repo.repo, |
| 84 | + issue_number: context.payload.issue.number, |
| 85 | + labels: ['0. Needs triage'], |
| 86 | + }) |
| 87 | + } |
0 commit comments