forked from dnd-side-project/dnd-13th-9-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (50 loc) · 1.61 KB
/
auto-label.yml
File metadata and controls
57 lines (50 loc) · 1.61 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
name: 'Auto Label PR by Commit Type'
on:
pull_request:
types: [opened, synchronize, reopened, edited]
permissions:
issues: write
pull-requests: write
jobs:
auto-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const labelMap = {
'feat': '✨feature',
'fix': '🐞bugfix',
'refactor': '🔄refactor',
'style': '🎨style',
'docs': '📚docs',
'test': '✅test',
'chore': '⚙️chore',
'deploy': '⬆️deploy',
};
const labels = new Set();
for (const commit of commits) {
const message = commit.commit.message.toLowerCase();
const match = message.match(/^(\w+):/);
if (match) {
const type = match[1];
if (labelMap[type]) {
labels.add(labelMap[type]);
}
}
}
if (labels.size > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: Array.from(labels),
});
}