diff --git a/.github/workflows/auto-issue.yml b/.github/workflows/auto-issue.yml index 9ad14dea..4b7b6d25 100644 --- a/.github/workflows/auto-issue.yml +++ b/.github/workflows/auto-issue.yml @@ -23,7 +23,7 @@ jobs: '[DOCS]': '๐Ÿ“ Docs', '[CI]': '๐Ÿ˜Ž DevOps', '[TEST]': '๐ŸŒŠ TEST', - '[REFACTOR]': '๐Ÿงน CHORE', + '[REFACTOR]': 'โ™ป Refactor', '[UI]': 'โŒš Timo-Design-system', '[STYLE]': 'โŒš Timo-Design-system', '[PERF]': 'โœจ Feature', diff --git a/.github/workflows/auto-label.yml b/.github/workflows/auto-label.yml index b4075691..c0dddd89 100644 --- a/.github/workflows/auto-label.yml +++ b/.github/workflows/auto-label.yml @@ -3,13 +3,18 @@ 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 @@ -17,14 +22,20 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} 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 @@ -86,17 +120,12 @@ jobs: 'yumin-kim2': 'โ™ฃ๏ธ ์œ ๋ฏผ', }; - 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], });