-
Notifications
You must be signed in to change notification settings - Fork 3
70 lines (63 loc) · 2.17 KB
/
Copy pathlabeler.yml
File metadata and controls
70 lines (63 loc) · 2.17 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
name: Auto-label PRs
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v6
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler.yml
- name: Label from commit emojis
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get all repository labels (with pagination) and build emoji-to-label map
const repoLabels = await github.paginate(
github.rest.issues.listLabelsForRepo,
{
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
}
);
const labelMap = {};
for (const label of repoLabels) {
// Extract the emoji from the label name (first character(s))
const match = label.name.match(/^(\p{Emoji}[\u200d\ufe0f]*)/u);
if (match) {
const emoji = match[1];
labelMap[emoji] = label.name;
}
}
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const labelsToAdd = new Set();
for (const commit of commits) {
const message = commit.commit.message;
// Check if message starts with an emoji
for (const [emoji, label] of Object.entries(labelMap)) {
if (message.startsWith(emoji)) {
labelsToAdd.add(label);
break;
}
}
}
if (labelsToAdd.size > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: Array.from(labelsToAdd)
});
}