[Feat] - AI 챗봇 api 연결 #23
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 Auto Setup | |
| 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 = ['KyeonJooni', 'tmdcks1103'].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); | |
| } | |
| } | |
| } | |
| // PR 제목 자동 설정 (이슈 제목 기반) | |
| // 예: 3-chore/project-setting → 이슈 #3 제목 → [Chore] 프로젝트 세팅 수정 | |
| const titleMatch = branchName.match(/^(\d+)-(\w+)\//); | |
| if (titleMatch) { | |
| const issueNumber = parseInt(titleMatch[1], 10); | |
| const prefix = titleMatch[2].charAt(0).toUpperCase() + titleMatch[2].slice(1); | |
| try { | |
| const { data: issue } = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| }); | |
| // 이슈 제목에서 prefix 태그 및 이슈 번호 제거 (예: "[Chore] #5 세팅" → "세팅") | |
| const issueTitle = issue.title.replace(/^\[.*?\]\s*-?\s*/, '').replace(/^#\d+\s*/, ''); | |
| const newTitle = `[${prefix}] ${issueTitle}`; | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| title: newTitle, | |
| }); | |
| } catch (error) { | |
| console.log('Failed to fetch issue title, falling back to branch name:', error.message); | |
| const fallbackTitle = decodeURIComponent(branchName.split('/')[1] || '').replace(/-/g, ' '); | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| title: `[${prefix}] ${fallbackTitle}`, | |
| }); | |
| } | |
| } | |
| // 브랜치명에서 라벨 추출 및 추가 | |
| 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); | |
| } | |
| } | |
| } |