rc-plugin/.github/workflows/auto-label.yml

140 lines
6.0 KiB
YAML

name: Auto Label Issues
on:
issues:
types: [opened]
jobs:
auto-label:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Add Labels Based on Content
uses: actions/github-script@v7
with:
script: |
const title = context.payload.issue.title.toLowerCase();
const body = context.payload.issue.body?.toLowerCase() || '';
const labels = [];
// 根据关键词自动添加标签
if (title.includes('bug') || title.includes('错误') || title.includes('问题') ||
body.includes('bug') || body.includes('错误') || body.includes('异常')) {
labels.push('bug');
}
if (title.includes('feature') || title.includes('功能') || title.includes('建议') ||
title.includes('enhancement') || body.includes('功能') || body.includes('建议')) {
labels.push('enhancement');
}
if (title.includes('doc') || title.includes('文档') || title.includes('说明') ||
body.includes('文档') || body.includes('说明') || body.includes('document')) {
labels.push('documentation');
}
if (title.includes('help') || title.includes('求助') || title.includes('question') ||
title.includes('如何') || title.includes('怎么') || body.includes('求助')) {
labels.push('question');
}
if (title.includes('性能') || title.includes('performance') || title.includes('优化') ||
body.includes('性能') || body.includes('慢') || body.includes('优化')) {
labels.push('performance');
}
if (title.includes('安全') || title.includes('security') ||
body.includes('安全') || body.includes('漏洞')) {
labels.push('security');
}
// 根据关键词和表单内容添加优先级标签
if (title.includes('紧急') || title.includes('urgent') || title.includes('critical') ||
body.includes('紧急') || body.includes('严重') || body.includes('紧急 - 完全无法使用') ||
body.includes('高 - 严重影响使用')) {
labels.push('priority/high');
} else if (title.includes('minor') || title.includes('小') || body.includes('小问题') ||
body.includes('低 - 轻微影响')) {
labels.push('priority/low');
} else {
labels.push('priority/medium');
}
// 根据平台关键词添加标签
if (title.includes('windows') || body.includes('windows')) {
labels.push('platform/windows');
}
if (title.includes('linux') || body.includes('linux')) {
labels.push('platform/linux');
}
if (title.includes('mac') || title.includes('darwin') || body.includes('mac')) {
labels.push('platform/mac');
}
// 根据组件关键词和表单选择添加标签
if (title.includes('bilibili') || title.includes('bili') || body.includes('bilibili') ||
body.includes('Bilibili下载')) {
labels.push('component/bilibili');
}
if (title.includes('tiktok') || title.includes('抖音') || body.includes('tiktok') ||
body.includes('抖音/TikTok下载')) {
labels.push('component/tiktok');
}
if (title.includes('youtube') || body.includes('youtube') || body.includes('YouTube下载')) {
labels.push('component/youtube');
}
if (title.includes('music') || title.includes('音乐') || body.includes('音乐') ||
body.includes('音乐功能')) {
labels.push('component/music');
}
if (title.includes('总结') || title.includes('summary') || body.includes('链接总结')) {
labels.push('component/summary');
}
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
});
}
console.log(`Added labels: ${labels.join(', ')}`);
- name: Add Milestone for Bugs
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.issue.labels.map(label => label.name);
const title = context.payload.issue.title.toLowerCase();
// 为bug类issue自动分配到下个版本里程碑
if (labels.includes('bug') || title.includes('bug') || title.includes('错误')) {
try {
// 获取所有开放的里程碑
const { data: milestones } = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'due_on',
direction: 'asc'
});
if (milestones.length > 0) {
// 分配到最近的里程碑
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
milestone: milestones[0].number
});
console.log(`Assigned to milestone: ${milestones[0].title}`);
}
} catch (error) {
console.log('No milestones found or error assigning milestone');
}
}