Skip to content

Commit 566146b

Browse files
committed
Only label issues if the issue itself is spammy
1 parent af6cae6 commit 566146b

3 files changed

Lines changed: 26 additions & 47 deletions

File tree

dist/index.js

Lines changed: 13 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,25 @@ import { extractFromEvent, shouldProcess } from './content-extractor.js'
99

1010
async function run(): Promise<void> {
1111
try {
12-
//------------------------------------------------------------
13-
// 0. Inputs & setup
14-
//------------------------------------------------------------
1512
const token = core.getInput('token')
1613
const __filename = fileURLToPath(import.meta.url)
1714
const __dirname = path.dirname(__filename)
1815
const promptsDir = path.resolve(__dirname, '..', 'prompts') // Use built-in prompts
1916
const spamLabel = core.getInput('spam-label')
2017
const aiLabel = core.getInput('ai-label')
2118

22-
// Initialize services - use GitHub Models instead of OpenAI
2319
const openai = new OpenAI({
24-
apiKey: token, // Use GitHub token instead of OpenAI API key
20+
apiKey: token,
2521
baseURL: 'https://models.github.ai/inference'
2622
})
2723
const octokit = github.getOctokit(token)
2824

29-
//------------------------------------------------------------
30-
// 1. Check if we should process this event
31-
//------------------------------------------------------------
3225
if (!shouldProcess(github.context)) {
3326
const event = github.context.eventName
3427
core.info(`Nothing to do for event ${event}.`)
3528
return
3629
}
3730

38-
//------------------------------------------------------------
39-
// 2. Extract content and identifiers
40-
//------------------------------------------------------------
4131
const { content, issueNumber, commentNodeId } = extractFromEvent(
4232
github.context
4333
)
@@ -47,30 +37,30 @@ async function run(): Promise<void> {
4737
return
4838
}
4939

50-
//------------------------------------------------------------
51-
// 3. Evaluate content against prompts
52-
//------------------------------------------------------------
5340
core.info('Evaluating content for spam and AI-generated content...')
5441
const flags = await evaluateContent(openai, promptsDir, content)
5542

5643
if (!flags.spam && !flags.ai) {
57-
core.info('No spam detected ✅')
44+
core.info('No spam or AI-generated content detected ✅')
5845
return
5946
}
6047

61-
//------------------------------------------------------------
62-
// 4. Take action: label or hide
63-
//------------------------------------------------------------
6448
const labels: string[] = []
65-
if (flags.spam) labels.push(spamLabel)
66-
if (flags.ai) labels.push(aiLabel)
6749

68-
if (issueNumber) {
50+
// Only add labels to issues if the issue content itself has the problem
51+
// (not if it's just a comment on the issue)
52+
if (issueNumber && !commentNodeId) {
53+
if (flags.spam) labels.push(spamLabel)
54+
if (flags.ai) labels.push(aiLabel)
55+
}
56+
57+
if (issueNumber && labels.length > 0) {
6958
await addLabels(octokit, github.context, issueNumber, labels)
7059
core.info(`Added labels [${labels.join(', ')}] to issue #${issueNumber}`)
7160
}
7261

73-
if (commentNodeId) {
62+
// Only minimize comments if they are spam, not just AI-generated
63+
if (commentNodeId && flags.spam) {
7464
await minimizeComment(octokit, commentNodeId)
7565
core.info(`Comment ${commentNodeId} minimized as spam`)
7666
}

0 commit comments

Comments
 (0)