Skip to content

Commit e52b59d

Browse files
committed
Fix: Check user comments instead of issue body
Now correctly filters for user comment replies (not the bot-created issue). Skips bot comments and only validates actual user contributions.
1 parent 672db85 commit e52b59d

1 file changed

Lines changed: 17 additions & 31 deletions

File tree

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Validate comment length
22

33
on:
4-
issues:
5-
types: [opened, edited]
64
issue_comment:
75
types: [created, edited]
86

@@ -19,47 +17,35 @@ jobs:
1917
with:
2018
script: |
2119
const minLength = 300;
22-
let content = '';
23-
let commentId = null;
20+
const comment = context.payload.comment;
21+
const commentAuthor = comment.user.login;
2422
25-
// Get the content to check
26-
if (context.payload.issue) {
27-
content = context.payload.issue.body || '';
28-
}
29-
if (context.payload.comment) {
30-
content = context.payload.comment.body || '';
31-
commentId = context.payload.comment.id;
23+
// Skip if comment is from bot
24+
if (commentAuthor === 'utterances-bot' || commentAuthor === 'github-actions') {
25+
console.log('Skipping bot comment');
26+
return;
3227
}
3328
3429
// Count characters (excluding whitespace)
35-
const charCount = content.trim().length;
30+
const charCount = comment.body.trim().length;
31+
32+
console.log(`Comment from ${commentAuthor}: ${charCount} characters`);
3633
3734
if (charCount < minLength) {
3835
// Post warning reply
39-
const reply = await github.rest.issues.createComment({
36+
await github.rest.issues.createComment({
4037
owner: context.repo.owner,
4138
repo: context.repo.repo,
4239
issue_number: context.issue.number,
4340
body: 'Your comment was flagged as too short and will be automatically deleted. Please elaborate further on your thoughts, I want to hear what you have to say!'
4441
});
4542
46-
// Delete the short comment if it's a reply comment
47-
if (commentId) {
48-
await github.rest.issues.deleteComment({
49-
owner: context.repo.owner,
50-
repo: context.repo.repo,
51-
comment_id: commentId
52-
});
53-
} else {
54-
// If it's the issue body, close the issue
55-
await github.rest.issues.update({
56-
owner: context.repo.owner,
57-
repo: context.repo.repo,
58-
issue_number: context.issue.number,
59-
state: 'closed',
60-
state_reason: 'not_planned'
61-
});
62-
}
43+
// Delete the short comment
44+
await github.rest.issues.deleteComment({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
comment_id: comment.id
48+
});
6349
64-
console.log(`Deleted comment - too short (${charCount} characters)`);
50+
console.log(`Deleted comment #${comment.id} - too short (${charCount} characters)`);
6551
}

0 commit comments

Comments
 (0)