File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Monitor and Delete Sensitive Discussion Comments
2+
3+ on :
4+ discussion_comment :
5+ types : [created, edited]
6+
7+ permissions :
8+ discussions : write
9+
10+ jobs :
11+ delete_sensitive_comments :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Set up Node.js
15+ uses : actions/setup-node@v2
16+ with :
17+ node-version : ' 14'
18+
19+ - name : Delete Comment with Sensitive Words
20+ env :
21+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22+ COMMENT_BODY : ${{ github.event.comment.body }}
23+ COMMENT_ID : ${{ github.event.comment.node_id }}
24+ run : |
25+ const { Octokit } = require("@octokit/core");
26+ const githubToken = process.env.GITHUB_TOKEN;
27+ const commentBody = process.env.COMMENT_BODY;
28+ const commentId = process.env.COMMENT_ID;
29+
30+ const sensitiveWords = ["孙悟空"]; // 在此处添加您的敏感词
31+
32+ const containsSensitiveWord = sensitiveWords.some(word =>
33+ commentBody.includes(word)
34+ );
35+
36+ if (containsSensitiveWord) {
37+ const octokit = new Octokit({ auth: githubToken });
38+ octokit.graphql(`
39+ mutation ($id: ID!) {
40+ deleteDiscussionComment(input: {id: $id}) {
41+ clientMutationId
42+ }
43+ }
44+ `, {
45+ id: commentId
46+ }).then(() => {
47+ console.log("Deleted a comment containing sensitive words.");
48+ }).catch(error => {
49+ console.error("Error deleting comment:", error);
50+ });
51+ } else {
52+ console.log("No sensitive words detected.");
53+ }
You can’t perform that action at this time.
0 commit comments