Skip to content

Workflow file for this run

name: Manage Labels on Issue Close
on:
issues:
types: [closed]
jobs:
manage-labels:
runs-on: ubuntu-latest
steps:
- name: Handle labels based on close reason
uses: actions/github-script@v6
with:
github-token: ${{ secrets.BOT }}
script: |
const { issue, repository } = context.payload;
const labelsToRemove = ['⭕ 等待处理', '🚧 正在处理'];
const closedReason = issue.state_reason;
// 移除旧标签
for (const label of labelsToRemove) {
try {
await github.rest.issues.removeLabel({
owner: repository.owner.login,
repo: repository.name,
issue_number: issue.number,
name: label
});
} catch (error) {
if (error.status !== 404) throw error;
}
}
// 根据关闭原因添加新标签
const reasonMapping = {
'completed': '👌 完成',
'not_planned': '❌ 忽略',
'duplicate': '❌ 重复'
};
if (reasonMapping[closedReason]) {
await github.rest.issues.addLabels({
owner: repository.owner.login,
repo: repository.name,
issue_number: issue.number,
labels: [reasonMapping[closedReason]]
});
}