This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
マニフェスト▶政策案 #182
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
}); | |
} | |