|
| 1 | +name: Auto Label Issues and PRs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + issues: |
| 7 | + types: [opened, reopened] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + issues: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + label-pr: |
| 16 | + name: Label Pull Requests |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: github.event_name == 'pull_request' |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Apply labels based on changed files |
| 24 | + uses: actions/labeler@v5 |
| 25 | + with: |
| 26 | + repo-token: "${{ secrets.GITHUB_TOKEN }}" |
| 27 | + configuration-path: .github/labeler.yml |
| 28 | + |
| 29 | + label-issue: |
| 30 | + name: Label Issues |
| 31 | + runs-on: ubuntu-latest |
| 32 | + if: github.event_name == 'issues' |
| 33 | + steps: |
| 34 | + - name: Label new issues with gssoc26 |
| 35 | + uses: actions/github-script@v7 |
| 36 | + with: |
| 37 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + script: | |
| 39 | + const issue = context.payload.issue; |
| 40 | + const body = (issue.body || '').toLowerCase(); |
| 41 | + const title = (issue.title || '').toLowerCase(); |
| 42 | +
|
| 43 | + const labelsToAdd = ['gssoc26']; |
| 44 | +
|
| 45 | + if (title.includes('bug') || body.includes('bug')) { |
| 46 | + labelsToAdd.push('bug'); |
| 47 | + } |
| 48 | + if (title.includes('feature') || body.includes('enhancement')) { |
| 49 | + labelsToAdd.push('enhancement'); |
| 50 | + } |
| 51 | + if (title.includes('docs') || body.includes('documentation')) { |
| 52 | + labelsToAdd.push('documentation'); |
| 53 | + } |
| 54 | + if (title.includes('level 1') || body.includes('level 1')) { |
| 55 | + labelsToAdd.push('level1'); |
| 56 | + } |
| 57 | + if (title.includes('level 2') || body.includes('level 2')) { |
| 58 | + labelsToAdd.push('level2'); |
| 59 | + } |
| 60 | + if (title.includes('level 3') || body.includes('level 3')) { |
| 61 | + labelsToAdd.push('level3'); |
| 62 | + } |
| 63 | +
|
| 64 | + await github.rest.issues.addLabels({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + issue_number: issue.number, |
| 68 | + labels: labelsToAdd |
| 69 | + }); |
0 commit comments