|
| 1 | +name: PR Automation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + auto-label-and-assign: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + fetch-depth: 0 |
| 15 | + |
| 16 | + - name: Get changed files |
| 17 | + id: files |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const { data: { files } } = await github.rest.pulls.listFiles({ |
| 22 | + owner: context.repo.owner, |
| 23 | + repo: context.repo.repo, |
| 24 | + pull_number: context.issue.number, |
| 25 | + }); |
| 26 | + |
| 27 | + const fileNames = files.map(f => f.filename); |
| 28 | + const labels = new Set(); |
| 29 | + |
| 30 | + fileNames.forEach(file => { |
| 31 | + if (file.match(/\.(ts|tsx|jsx|js)$/)) labels.add('typescript'); |
| 32 | + if (file.match(/\.(css|scss|postcss)$/)) labels.add('styling'); |
| 33 | + if (file.match(/test|spec/)) labels.add('tests'); |
| 34 | + if (file.match(/package\.json|tsconfig|eslint|tailwind/)) labels.add('configuration'); |
| 35 | + if (file.match(/README|\.md$/)) labels.add('documentation'); |
| 36 | + if (file.match(/next\.config|public/)) labels.add('build'); |
| 37 | + }); |
| 38 | + |
| 39 | + core.setOutput('labels', Array.from(labels).join(',')); |
| 40 | +
|
| 41 | + - name: Auto-label PR |
| 42 | + if: steps.files.outputs.labels != '' |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const labels = '${{ steps.files.outputs.labels }}'.split(',').filter(l => l); |
| 47 | + if (labels.length > 0) { |
| 48 | + github.rest.issues.addLabels({ |
| 49 | + issue_number: context.issue.number, |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + labels: labels |
| 53 | + }); |
| 54 | + } |
| 55 | +
|
| 56 | + - name: Auto-assign PR to author |
| 57 | + uses: actions/github-script@v7 |
| 58 | + with: |
| 59 | + script: | |
| 60 | + github.rest.issues.addAssignees({ |
| 61 | + issue_number: context.issue.number, |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + assignees: [context.payload.pull_request.user.login] |
| 65 | + }).catch(err => { |
| 66 | + console.log('Could not assign author: ' + err.message); |
| 67 | + }) |
0 commit comments