|
| 1 | +name: Auto Label Pull Requests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - synchronize |
| 9 | + |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + |
| 17 | + # ------------------------------------------------------------ |
| 18 | + # Auto-label new pull requests |
| 19 | + # ------------------------------------------------------------ |
| 20 | + auto-label-new-prs: |
| 21 | + if: github.event_name == 'pull_request' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Apply labels to PR |
| 26 | + uses: actions/github-script@v7 |
| 27 | + with: |
| 28 | + script: | |
| 29 | + const pr = context.payload.pull_request; |
| 30 | + const branch = pr.head.ref; |
| 31 | +
|
| 32 | + let labels = ['gssoc-26']; |
| 33 | +
|
| 34 | + if (branch.startsWith('fix/')) { |
| 35 | + labels.push('bug'); |
| 36 | + } |
| 37 | +
|
| 38 | + if (branch.startsWith('feat/')) { |
| 39 | + labels.push('enhancement'); |
| 40 | + } |
| 41 | +
|
| 42 | + if (branch.startsWith('docs/')) { |
| 43 | + labels.push('documentation'); |
| 44 | + } |
| 45 | +
|
| 46 | + if (branch.startsWith('style/')) { |
| 47 | + labels.push('ui'); |
| 48 | + } |
| 49 | +
|
| 50 | + if (branch.startsWith('test/')) { |
| 51 | + labels.push('testing'); |
| 52 | + } |
| 53 | +
|
| 54 | + if (branch.startsWith('refactor/')) { |
| 55 | + labels.push('refactor'); |
| 56 | + } |
| 57 | +
|
| 58 | + await github.rest.issues.addLabels({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + issue_number: pr.number, |
| 62 | + labels |
| 63 | + }); |
| 64 | +
|
| 65 | + # ------------------------------------------------------------ |
| 66 | + # Apply labels to ALL existing PRs |
| 67 | + # ------------------------------------------------------------ |
| 68 | + label-existing-prs: |
| 69 | + if: github.event_name == 'workflow_dispatch' |
| 70 | + runs-on: ubuntu-latest |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Label all existing PRs |
| 74 | + uses: actions/github-script@v7 |
| 75 | + with: |
| 76 | + script: | |
| 77 | + const pulls = await github.paginate( |
| 78 | + github.rest.pulls.list, |
| 79 | + { |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + state: 'all' |
| 83 | + } |
| 84 | + ); |
| 85 | +
|
| 86 | + for (const pr of pulls) { |
| 87 | +
|
| 88 | + const branch = pr.head.ref; |
| 89 | + let labels = ['gssoc-26']; |
| 90 | +
|
| 91 | + if (branch.startsWith('fix/')) { |
| 92 | + labels.push('bug'); |
| 93 | + } |
| 94 | +
|
| 95 | + if (branch.startsWith('feat/')) { |
| 96 | + labels.push('enhancement'); |
| 97 | + } |
| 98 | +
|
| 99 | + if (branch.startsWith('docs/')) { |
| 100 | + labels.push('documentation'); |
| 101 | + } |
| 102 | +
|
| 103 | + if (branch.startsWith('style/')) { |
| 104 | + labels.push('ui'); |
| 105 | + } |
| 106 | +
|
| 107 | + if (branch.startsWith('test/')) { |
| 108 | + labels.push('testing'); |
| 109 | + } |
| 110 | +
|
| 111 | + if (branch.startsWith('refactor/')) { |
| 112 | + labels.push('refactor'); |
| 113 | + } |
| 114 | +
|
| 115 | + await github.rest.issues.addLabels({ |
| 116 | + owner: context.repo.owner, |
| 117 | + repo: context.repo.repo, |
| 118 | + issue_number: pr.number, |
| 119 | + labels |
| 120 | + }); |
| 121 | +
|
| 122 | + console.log(`Labels added to PR #${pr.number}`); |
| 123 | + } |
0 commit comments