This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
60 lines (50 loc) · 1.77 KB
/
add-label.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
# Automatically adds labels to issues based on policy categories
name: Add issue tags
on:
issues:
types: [opened]
permissions:
issues: write
contents: read
jobs:
add_label:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Parse issue content and add labels
id: labeler
uses: actions/github-script@v7
with:
script: |
const issueBody = context.payload.issue.body;
const labelsToAdd = [];
const policyVisionSectionMatch = issueBody.match(/## 政策ビジョン([\s\S]*)## 政策/);
const policyVisionSection = policyVisionSectionMatch ? policyVisionSectionMatch[1] : '';
const categories = [
{ regex: /^経済$/, label: '経済' },
{ regex: /^医療・防災$/, label: '医療・防災' },
{ regex: /^教育・子育て$/, label: '教育・子育て' },
{ regex: /^行政$/, label: '行政' },
{ regex: /^民主主義$/, label: '民主主義' },
{ regex: /^その他$/, label: 'その他' },
];
policyVisionSection.split('\n').forEach(line => {
line.split(', ').forEach(item => {
categories.forEach(category => {
if (category.regex.test(item)) {
console.log(`Match: ${category.label}`);
labelsToAdd.push(category.label);
}
});
});
});
if (labelsToAdd.length > 0) {
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labelsToAdd
});
}