-
Notifications
You must be signed in to change notification settings - Fork 1.4k
46 lines (45 loc) · 1.59 KB
/
auto-label-conventional-commits.yaml
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
name: "Auto Label Conventional Commits"
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
label_issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/labeler@v4
with:
script: |
const github = require('@actions/github');
const core = require('@actions/core');
const token = core.getInput('github-token', { required: true });
const octokit = github.getOctokit(token);
const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title;
const labelMapping = {
'feat:': 'type: feature request',
'perf:': 'type: enhancement',
'fix:': 'type: bug',
'docs:': 'type: documentation',
'ci:': 'type: ci',
'build:': 'type: ci',
'chore:': 'type: chore',
'test:': 'type: chore',
'style:': 'type: chore',
'refactor:': 'type: chore',
};
for (const [prefix, label] of Object.entries(labelMapping)) {
if (title.startsWith(prefix)) {
const issue_number = context.payload.issue ? context.issue.number : context.payload.pull_request.number;
octokit.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
labels: [label],
});
break;
}
}