-
Notifications
You must be signed in to change notification settings - Fork 0
[CI] 이슈 작성자 라벨 자동 부착 자동화 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec3c384
ci(root): 이슈 작성자 라벨 자동 부착 추가 (#8)
kimminna 59e5707
ci(root): label-by-prefix·author를 label-pr로 통합, job 최소 권한 분리 (#8)
kimminna 78565e9
ci(root): label-by-files job에 contents: read 권한 추가 (#8)
kimminna 1d28219
ci(root): label-pr 잡 라벨 중복 처리 방지 및 순차 실행 적용 (#8)
kimminna 222fcfa
ci(root): 이슈 [REFACTOR] 라벨 매핑을 PR과 통일 (#8)
kimminna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,39 @@ name: Auto Label | |
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, edited, reopened] | ||
| issues: | ||
| types: [opened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| label-by-files: | ||
| if: github.event_name == 'pull_request' | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/labeler@v5 | ||
| with: | ||
| repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
kimminna marked this conversation as resolved.
|
||
| sync-labels: false | ||
|
|
||
| label-by-prefix: | ||
| if: github.event.action != 'synchronize' | ||
| label-pr: | ||
| if: github.event_name == 'pull_request' && github.event.action != 'synchronize' | ||
| needs: label-by-files | ||
| permissions: | ||
| pull-requests: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const title = context.payload.pull_request.title; | ||
| const pr = context.payload.pull_request; | ||
| const action = context.payload.action; | ||
| const prNumber = pr.number; | ||
|
|
||
| const prefixMap = { | ||
| '[FEAT]': '✨ Feature', | ||
| '[FIX]': '🐛 Bug', | ||
|
|
@@ -39,41 +50,64 @@ jobs: | |
| '[PERF]': '✨ Feature', | ||
| '[API]': '🌟 API', | ||
| }; | ||
|
|
||
| // edited 이벤트는 본문 수정만으로도 트리거되므로 제목 변경 여부를 확인 | ||
| if (context.payload.action === 'edited' && !context.payload.changes?.title) return; | ||
|
|
||
| const allPrefixLabels = [...new Set(Object.values(prefixMap))]; | ||
| const match = Object.entries(prefixMap).find(([prefix]) => title.startsWith(prefix)); | ||
| const authorMap = { | ||
| 'kimminna': '♦️ 민아', | ||
| 'ehye1': '♥️ 혜원', | ||
| 'jjangminii': '♠️ 정민', | ||
| 'yumin-kim2': '♣️ 유민', | ||
| }; | ||
|
|
||
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| issue_number: prNumber, | ||
| }); | ||
| const currentLabelNames = new Set(currentLabels.map(l => l.name)); | ||
|
|
||
| for (const label of currentLabels) { | ||
| if (allPrefixLabels.includes(label.name)) { | ||
| await github.rest.issues.removeLabel({ | ||
| // --- prefix 라벨 --- | ||
| // edited 이벤트는 본문 수정만으로도 트리거되므로 제목 변경 여부를 확인 | ||
| if (action !== 'edited' || context.payload.changes?.title) { | ||
| const allPrefixLabels = [...new Set(Object.values(prefixMap))]; | ||
| const match = Object.entries(prefixMap).find(([prefix]) => pr.title.startsWith(prefix)); | ||
| const desiredLabel = match ? match[1] : null; | ||
|
|
||
| for (const label of currentLabels) { | ||
| if (allPrefixLabels.includes(label.name) && label.name !== desiredLabel) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| name: label.name, | ||
| }); | ||
| } | ||
| } | ||
| if (desiredLabel && !currentLabelNames.has(desiredLabel)) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| name: label.name, | ||
| issue_number: prNumber, | ||
| labels: [desiredLabel], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (!match) return; | ||
|
|
||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| labels: [match[1]], | ||
| }); | ||
| // --- 작성자 라벨 (opened / reopened 시에만, 이미 있으면 생략) --- | ||
| if (action === 'opened' || action === 'reopened') { | ||
| const label = authorMap[pr.user.login]; | ||
| if (label && !currentLabelNames.has(label)) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| labels: [label], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| label-by-author: | ||
| if: github.event.action == 'opened' || github.event.action == 'reopened' | ||
| label-issues: | ||
| if: github.event_name == 'issues' | ||
| permissions: | ||
| issues: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/github-script@v7 | ||
|
kimminna marked this conversation as resolved.
|
||
|
|
@@ -86,17 +120,12 @@ jobs: | |
| 'yumin-kim2': '♣️ 유민', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엇 label-issues authorMap에 저만 있는 것 같아요..! 나머지 분들 매핑이 빠진 것 같은데 확인 부탁드려요 🙏 |
||
| }; | ||
|
|
||
| const author = context.payload.pull_request.user.login; | ||
| const label = authorMap[author]; | ||
|
|
||
| if (!label) { | ||
| console.log(`"${author}"에 대한 라벨 매핑이 없습니다.`); | ||
| return; | ||
| } | ||
| const label = authorMap[context.payload.issue.user.login]; | ||
| if (!label) return; | ||
|
|
||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| issue_number: context.payload.issue.number, | ||
| labels: [label], | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.