-
Notifications
You must be signed in to change notification settings - Fork 1
60 lines (52 loc) · 1.78 KB
/
auto_labeling.yml
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
name: Auto Label PR
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
auto-label:
runs-on: ubuntu-latest
steps:
# PR 이벤트 트리거
- name: Checkout code
uses: actions/checkout@v3
# 커밋 메시지 키워드에 따라 라벨 추가
- name: Add labels based on commit messages
uses: actions/github-script@v6
with:
script: |
const commitKeywords = {
feat: 'feature',
fix: 'bug',
chore: 'chore',
docs: 'documentation',
style: 'style',
refactor: 'refactor',
test: 'test',
perf: 'performance',
};
// context와 github는 기본적으로 제공됨
const { owner, repo } = context.repo;
const pullRequestNumber = context.payload.pull_request.number;
const { data: commits } = await github.rest.pulls.listCommits({
owner,
repo,
pull_number: pullRequestNumber,
});
const labelsToAdd = new Set();
commits.forEach(commit => {
const keyword = commit.commit.message.split(':')[0].trim();
if (commitKeywords[keyword]) {
labelsToAdd.add(commitKeywords[keyword]);
}
});
if (labelsToAdd.size > 0) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pullRequestNumber,
labels: [...labelsToAdd],
});
console.log('Labels added:', [...labelsToAdd]);
} else {
console.log('No matching labels found for commits.');
}