-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (138 loc) · 5.5 KB
/
Copy pathauto-label.yml
File metadata and controls
151 lines (138 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: 👽 Auto Label
on:
pull_request:
types: [opened, synchronize, edited, reopened]
issues:
types: [opened]
permissions:
contents: read
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 }}
sync-labels: false
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 pr = context.payload.pull_request;
const action = context.payload.action;
const prNumber = pr.number;
const prefixMap = {
'[FEAT]': '✨ Feature',
'[FIX]': '🐛 Bug',
'[CHORE]': '🧹 CHORE',
'[INIT]': '🛠️ Setup',
'[DOCS]': '📝 Docs',
'[CI]': '😎 DevOps',
'[TEST]': '🌊 TEST',
'[REFACTOR]': '♻ Refactor',
'[UI]': '⌚ Timo-Design-system',
'[STYLE]': '⌚ Timo-Design-system',
'[PERF]': '✨ Feature',
'[API]': '🌟 API',
};
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: prNumber,
});
const currentLabelNames = new Set(currentLabels.map(l => l.name));
// labeler.yml이 파일 경로 기준으로 관리하는 라벨은 파일 변경 여부로 보호
// label-by-files job이 추가했을 수 있으므로 prefix 기반 제거 대상에서 제외
const changedFiles = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
per_page: 100,
});
const fileLabelProtection = new Map([
['⌚ Timo-Design-system', 'packages/timo-design-system/'],
['⏰ Timo-web', 'apps/timo-web/'],
]);
const protectedByFiles = new Set(
[...fileLabelProtection.entries()]
.filter(([, pathPrefix]) => changedFiles.some(f => f.filename.startsWith(pathPrefix)))
.map(([label]) => label)
);
// --- 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) {
// 파일 변경으로 인해 label-by-files가 추가한 라벨은 제거하지 않음
if (protectedByFiles.has(label.name)) continue;
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: prNumber,
labels: [desiredLabel],
});
}
}
// --- 작성자 라벨 (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-issues:
if: github.event_name == 'issues'
permissions:
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const authorMap = {
'kimminna': '♦️ 민아',
'ehye1': '♥️ 혜원',
'jjangminii': '♠️ 정민',
'yumin-kim2': '♣️ 유민',
};
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.issue.number,
labels: [label],
});