Skip to content

Commit 672db85

Browse files
committed
Fix comment validator - use deleteComment API instead of deleteIssue
1 parent f7c4c31 commit 672db85

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

.github/workflows/comment-validator.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,46 @@ jobs:
2020
script: |
2121
const minLength = 300;
2222
let content = '';
23-
let isComment = false;
23+
let commentId = null;
2424
2525
// Get the content to check
2626
if (context.payload.issue) {
2727
content = context.payload.issue.body || '';
28-
isComment = false;
2928
}
3029
if (context.payload.comment) {
3130
content = context.payload.comment.body || '';
32-
isComment = true;
31+
commentId = context.payload.comment.id;
3332
}
3433
3534
// Count characters (excluding whitespace)
3635
const charCount = content.trim().length;
3736
3837
if (charCount < minLength) {
39-
// Post reply
40-
await github.rest.issues.createComment({
38+
// Post warning reply
39+
const reply = await github.rest.issues.createComment({
4140
owner: context.repo.owner,
4241
repo: context.repo.repo,
4342
issue_number: context.issue.number,
4443
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!'
4544
});
4645
47-
// Close issue
48-
await github.rest.issues.update({
49-
owner: context.repo.owner,
50-
repo: context.repo.repo,
51-
issue_number: context.issue.number,
52-
state: 'closed',
53-
state_reason: 'not_planned'
54-
});
55-
56-
// Delete issue
57-
await github.rest.issues.deleteIssue({
58-
owner: context.repo.owner,
59-
repo: context.repo.repo,
60-
issue_number: context.issue.number
61-
});
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+
}
6263
63-
console.log(`Deleted issue #${context.issue.number} - too short (${charCount} characters)`);
64+
console.log(`Deleted comment - too short (${charCount} characters)`);
6465
}

0 commit comments

Comments
 (0)