Skip to content

Commit 3917896

Browse files
LiuqingHeAIclaude
andcommitted
ci: support comment testing in spam guard dispatch entry
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4ad238c commit 3917896

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

.github/workflows/issue-spam-guard.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ on:
1313
workflow_dispatch:
1414
inputs:
1515
issue_number:
16-
description: '要测试的 issue 号(读取内容→判断→命中即删除,不受 owner 白名单限制)'
17-
required: true
16+
description: '要测试的 issue 号(留空则测试 comment_id)'
17+
required: false
18+
type: string
19+
comment_id:
20+
description: '要测试的评论 id(填了则测评论,优先于 issue_number)'
21+
required: false
1822
type: string
1923

2024
permissions:
@@ -36,6 +40,25 @@ jobs:
3640
const model = process.env.AI_MODEL || 'gpt-4o-mini';
3741
if (!baseUrl || !apiKey) { core.setFailed('缺少 AI_BASE_URL 或 AI_API_KEY secret'); return; }
3842
43+
const commentId = (context.payload.inputs.comment_id || '').trim();
44+
45+
if (commentId) {
46+
// ---- 测试评论 ----
47+
const { data: comment } = await github.rest.issues.getComment({
48+
owner: context.repo.owner, repo: context.repo.repo, comment_id: Number(commentId),
49+
});
50+
const text = `这是某 issue 下的一条评论:\n${comment.body || ''}`;
51+
const verdict = await classify(text, { fetch, core, baseUrl, apiKey, model, prompt: process.env.AI_PROMPT });
52+
core.notice(`评论分类结果: spam=${verdict?.spam} 理由=${verdict?.reason || '无'}`);
53+
if (!verdict || !verdict.spam) { core.info('非垃圾评论,保留。'); return; }
54+
await github.rest.issues.deleteComment({
55+
owner: context.repo.owner, repo: context.repo.repo, comment_id: Number(commentId),
56+
});
57+
core.notice(`已删除垃圾评论 (comment id ${commentId})`);
58+
return;
59+
}
60+
61+
// ---- 测试 issue ----
3962
const number = Number(context.payload.inputs.issue_number);
4063
const { data: issue } = await github.rest.issues.get({
4164
owner: context.repo.owner, repo: context.repo.repo, issue_number: number,

0 commit comments

Comments
 (0)