|
| 1 | +name: PR Automation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + issues: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + auto-setup: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Auto assign and add reviewers |
| 17 | + uses: actions/github-script@v7 |
| 18 | + with: |
| 19 | + script: | |
| 20 | + const prNumber = context.payload.pull_request.number; |
| 21 | + const prAuthor = context.payload.pull_request.user.login; |
| 22 | + const branchName = context.payload.pull_request.head.ref; |
| 23 | + const currentAssignees = context.payload.pull_request.assignees || []; |
| 24 | + const currentReviewers = context.payload.pull_request.requested_reviewers || []; |
| 25 | +
|
| 26 | + // Assignee 설정 |
| 27 | + if (currentAssignees.length === 0) { |
| 28 | + await github.rest.issues.addAssignees({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + issue_number: prNumber, |
| 32 | + assignees: [prAuthor] |
| 33 | + }); |
| 34 | + } |
| 35 | +
|
| 36 | + // Reviewer 추가 |
| 37 | + if (currentReviewers.length === 0) { |
| 38 | + const reviewers = ['YeBeenChoi', 'jwj0620gcu'].filter(r => r !== prAuthor); |
| 39 | + if (reviewers.length > 0) { |
| 40 | + try { |
| 41 | + await github.rest.pulls.requestReviewers({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: context.repo.repo, |
| 44 | + pull_number: prNumber, |
| 45 | + reviewers: reviewers |
| 46 | + }); |
| 47 | + } catch (error) { |
| 48 | + console.log('Failed to add reviewers:', error.message); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +
|
| 53 | + // 브랜치명에서 라벨 추출 및 추가 |
| 54 | + const labelMatch = branchName.match(/(?:^\d+-)?(\w+)\//); |
| 55 | + if (labelMatch) { |
| 56 | + const labelMap = { |
| 57 | + 'feat': '✨Feature', |
| 58 | + 'fix': '🐛BugFix', |
| 59 | + 'hotfix': '🚨Hotfix', |
| 60 | + 'refactor': '♻️Refactor', |
| 61 | + 'test': '✅Test', |
| 62 | + 'docs': '📝Docs', |
| 63 | + 'chore': '🛠️ Chore' |
| 64 | + }; |
| 65 | + const labelToAdd = labelMap[labelMatch[1].toLowerCase()]; |
| 66 | +
|
| 67 | + if (labelToAdd) { |
| 68 | + try { |
| 69 | + await github.rest.issues.addLabels({ |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + issue_number: prNumber, |
| 73 | + labels: [labelToAdd] |
| 74 | + }); |
| 75 | + } catch (error) { |
| 76 | + console.log('Failed to add label:', error.message); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
0 commit comments