Skip to content
Merged
47 changes: 47 additions & 0 deletions .github/workflows/prevent_issue_close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Prevent Issue Close with not_fixed Label

on:
issues:
types: [closed]

permissions:
issues: write

jobs:
prevent-close:
runs-on: ubuntu-latest
steps:
- name: Check not_fixed label and reopen if needed
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const labels = issue.labels.map(label => label.name.toLowerCase());
const issueNumber = issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;

// 检查是否存在 not_fixed 标签
if (labels.includes('not_fixed')) {
console.log(`Issue #${issueNumber} has 'not_fixed' label, preventing closure...`);

// 重新打开 issue
await github.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issueNumber,
state: 'open'
});

// 添加评论说明
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: issueNumber,
body: `⚠️ **此 Issue 无法关闭**\n\n该 Issue 带有 \`not_fixed\` 标签,表示问题尚未完全解决。\n\n修复此问题的 PR 可能已经合入,请 @${issue.user.login} 验证后移除 \`not_fixed\` 标签并手动关闭此 Issue。`
});
Comment on lines +40 to +42
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow posts a Chinese-only comment body when preventing closure. This repo already splits CN/EN automation by detecting Chinese characters in the issue title (see .github/workflows/issue_auto_reply_cn.yml and issue_auto_reply_en.yml), so English issues will receive an unreadable message here. Consider reusing the same hasChinese detection and provide an English message (or a bilingual message) accordingly.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +42
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On every close attempt with not_fixed, this workflow will reopen the issue and create a new comment. If someone closes/re-closes repeatedly (or automation retries), this can spam the issue thread with duplicate bot messages. Consider making the comment idempotent (e.g., search existing comments for a unique marker and skip creating a new one, or update/edit an existing bot comment).

Copilot uses AI. Check for mistakes.

console.log(`Issue #${issueNumber} has been reopened due to 'not_fixed' label`);
} else {
console.log(`Issue #${issueNumber} does not have 'not_fixed' label, allowing closure`);
}