Update README.md #47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Automation | |
| on: | |
| pull_request: | |
| types: [opened, reopened] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| auto-setup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Auto assign and add reviewers | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = context.payload.pull_request.number; | |
| const prAuthor = context.payload.pull_request.user.login; | |
| const branchName = context.payload.pull_request.head.ref; | |
| const currentAssignees = context.payload.pull_request.assignees || []; | |
| const currentReviewers = context.payload.pull_request.requested_reviewers || []; | |
| // Assignee 설정 | |
| if (currentAssignees.length === 0) { | |
| await github.rest.issues.addAssignees({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| assignees: [prAuthor] | |
| }); | |
| } | |
| // Reviewer 추가 | |
| if (currentReviewers.length === 0) { | |
| const reviewers = ['YeBeenChoi', 'jwj0620gcu', 'KyeongJooni'].filter(r => r !== prAuthor); | |
| if (reviewers.length > 0) { | |
| try { | |
| await github.rest.pulls.requestReviewers({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| reviewers: reviewers | |
| }); | |
| } catch (error) { | |
| console.log('Failed to add reviewers:', error.message); | |
| } | |
| } | |
| } | |
| // 브랜치명에서 라벨 추출 및 추가 | |
| const labelMatch = branchName.match(/(?:^\d+-)?(\w+)\//); | |
| if (labelMatch) { | |
| const labelMap = { | |
| 'feat': '✨Feature', | |
| 'fix': '🐛BugFix', | |
| 'hotfix': '🚨Hotfix', | |
| 'refactor': '♻️Refactor', | |
| 'test': '✅Test', | |
| 'docs': '📝Docs', | |
| 'chore': '🛠️ Chore' | |
| }; | |
| const labelToAdd = labelMap[labelMatch[1].toLowerCase()]; | |
| if (labelToAdd) { | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: [labelToAdd] | |
| }); | |
| } catch (error) { | |
| console.log('Failed to add label:', error.message); | |
| } | |
| } | |
| } |