-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (180 loc) · 7.88 KB
/
pr-labeler.yml
File metadata and controls
211 lines (180 loc) · 7.88 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: PR Labeler
on:
pull_request:
types: [opened, synchronize, edited]
jobs:
# ==========================================================================
# Size Label - PR 크기에 따른 라벨 (변경 시 업데이트)
# ==========================================================================
size-label:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Label PR by Size
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const totalChanges = pr.additions + pr.deletions;
console.log(`📊 PR #${prNumber} 변경: +${pr.additions} -${pr.deletions} (총 ${totalChanges} lines)`);
const sizeLabels = {
'size/XS': { max: 10, color: '3CBF00' },
'size/S': { max: 50, color: '5D9801' },
'size/M': { max: 200, color: 'FBCA04' },
'size/L': { max: 500, color: 'FFA500' },
'size/XL': { max: Infinity, color: 'D93F0B' }
};
let newSizeLabel = 'size/XL';
for (const [label, config] of Object.entries(sizeLabels)) {
if (totalChanges <= config.max) {
newSizeLabel = label;
break;
}
}
// 현재 라벨 확인
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const currentSizeLabel = currentLabels.find(l => l.name.startsWith('size/'));
// 같은 라벨이면 스킵
if (currentSizeLabel?.name === newSizeLabel) {
console.log(`✅ 이미 올바른 크기 라벨: ${newSizeLabel}`);
return;
}
// 기존 size 라벨 제거
if (currentSizeLabel) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: currentSizeLabel.name
});
}
// 라벨이 없으면 생성
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: newSizeLabel
});
} catch (error) {
if (error.status === 404) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: newSizeLabel,
color: sizeLabels[newSizeLabel].color,
description: `PR size: ${newSizeLabel.replace('size/', '')}`
});
}
}
// 새 라벨 추가
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [newSizeLabel]
});
console.log(`✅ 크기 라벨 적용: ${newSizeLabel}`);
# ==========================================================================
# Type Label - PR 커밋들에서 타입 추출 (없을 때만 추가)
# ==========================================================================
type-label:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Label PR by Commit Types
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
// 지원하는 타입 라벨 정의
const typeLabels = {
'feat': { color: '0E8A16', description: '새로운 기능' },
'fix': { color: 'D93F0B', description: '버그 수정' },
'refactor': { color: '1D76DB', description: '리팩토링' },
'design': { color: 'F9D0C4', description: 'UI/디자인 변경' },
'style': { color: 'FEF2C0', description: '코드 스타일 변경' },
'docs': { color: '0075CA', description: '문서 수정' },
'test': { color: 'BFD4F2', description: '테스트 코드' },
'chore': { color: 'D4C5F9', description: '기타 변경사항' },
'init': { color: '5319E7', description: '초기 생성' },
'rename': { color: 'C2E0C6', description: '파일/폴더명 변경' },
'remove': { color: 'B60205', description: '파일 삭제' },
'cicd': { color: 'FBCA04', description: 'CI/CD 관련' }
};
const typeKeys = Object.keys(typeLabels);
const typePattern = new RegExp(`(?:^|\\s)(${typeKeys.join('|')})(?:\\([^)]*\\))?:`, 'i');
// PR의 커밋 목록 가져오기
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
console.log(`📝 PR #${prNumber} 커밋 수: ${commits.length}`);
// 각 커밋에서 타입 추출 (중복 제거)
const detectedTypes = new Set();
for (const commit of commits) {
const message = commit.commit.message.split('\n')[0]; // 첫 줄만
const match = message.match(typePattern);
if (match) {
detectedTypes.add(match[1].toLowerCase());
}
console.log(` - ${message.substring(0, 60)}${message.length > 60 ? '...' : ''}`);
}
console.log(`🔍 감지된 타입: ${[...detectedTypes].join(', ') || '없음'}`);
if (detectedTypes.size === 0) {
console.log('⚠️ 커밋에서 타입을 찾을 수 없습니다.');
return;
}
// 현재 라벨 확인
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const currentLabelNames = currentLabels.map(l => l.name);
// 추가할 타입 라벨 필터링 (이미 있는 것 제외)
const labelsToAdd = [...detectedTypes].filter(type => !currentLabelNames.includes(type));
if (labelsToAdd.length === 0) {
console.log('✅ 모든 타입 라벨이 이미 존재합니다.');
return;
}
// 라벨이 없으면 생성
for (const type of labelsToAdd) {
const labelConfig = typeLabels[type];
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: type
});
} catch (error) {
if (error.status === 404) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: type,
color: labelConfig.color,
description: labelConfig.description
});
}
}
}
// 타입 라벨 추가
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
console.log(`✅ 타입 라벨 추가: ${labelsToAdd.join(', ')}`);