diff --git a/.github/workflows/pr-checklist-check.yml b/.github/workflows/pr-checklist-check.yml index 01c97f4cb..fb3fdff3a 100644 --- a/.github/workflows/pr-checklist-check.yml +++ b/.github/workflows/pr-checklist-check.yml @@ -13,77 +13,42 @@ jobs: issues: write steps: - - name: Check if user checked "我没有认真阅读" + - name: Check checklist id: check uses: actions/github-script@v7 with: script: | - const body = context.payload.pull_request.body || ''; + const body = context.payload.pull_request.body || ""; - // 宽松匹配 checklist - const regex = /-\s*\[\s*x\s*\]\s*.*我\s*\*?\*?没有\s*\*?\*?认真阅读/im; + const regex = /-\s*\[\s*x\s*\].*没有.*认真阅读/i; - const isBad = regex.test(body); + const bad = regex.test(body); - core.setOutput("bad", isBad); - - - name: Comment and close PR if checklist violated + core.setOutput("bad", bad); + + - name: Close PR if violated if: steps.check.outputs.bad == 'true' uses: actions/github-script@v7 with: script: | const pr = context.payload.pull_request; - const prNumber = pr.number; - const author = pr.user.login; - // 防止重复评论 - const comments = await github.rest.issues.listComments({ + await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: prNumber + issue_number: pr.number, + body: `👋 @${pr.user.login} + +检测到你勾选了 **“我没有认真阅读”**。 + +请重新阅读 PR 模板并重新提交 PR。 + +This PR has been automatically closed.` }); - const already = comments.data.some(c => - c.body.includes("PR 未通过检查清单校验") - ); - - if (!already) { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: ` -👋 @${author} - -您的 PR 未通过检查清单校验 —— 检测到您勾选了「我**没有**认真阅读以上内容,直接提交」。 - -请按照以下规则重新提交 PR: - -1. 请仔细阅读 PR 模板中的所有说明。 -2. 本次开发请 **基于 \`dev\` 分支** 进行,并将 PR 目标分支设置为 **开发分支(\`dev\`)**。 -3. 完成检查后重新提交 PR。 - -本 PR 已自动关闭,请按规范重新拉起。感谢贡献! 🙏 - ---- - -Your PR failed the checklist validation — the item -"I **did not** read the instructions carefully before submitting" was checked. - -Please: - -1. Read the PR template carefully -2. Base your work on the **\`dev\` branch** -3. Open a new PR after fixing the checklist - -This PR has been automatically closed. Thank you! 🙏 -` - }); - } - await github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: prNumber, + pull_number: pr.number, state: "closed" }); \ No newline at end of file