Delete Comments Containing Sensitive Words #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Monitor and Delete Sensitive Discussion Comments | |
| on: | |
| discussion_comment: | |
| types: [created, edited] | |
| permissions: | |
| discussions: write | |
| jobs: | |
| delete_sensitive_comments: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: '14' | |
| - name: Delete Comment with Sensitive Words | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| COMMENT_BODY: ${{ github.event.comment.body }} | |
| COMMENT_ID: ${{ github.event.comment.node_id }} | |
| run: | | |
| const { Octokit } = require("@octokit/core"); | |
| const githubToken = process.env.GITHUB_TOKEN; | |
| const commentBody = process.env.COMMENT_BODY; | |
| const commentId = process.env.COMMENT_ID; | |
| const sensitiveWords = ["孙悟空"]; // 在此处添加您的敏感词 | |
| const containsSensitiveWord = sensitiveWords.some(word => | |
| commentBody.includes(word) | |
| ); | |
| if (containsSensitiveWord) { | |
| const octokit = new Octokit({ auth: githubToken }); | |
| octokit.graphql(` | |
| mutation ($id: ID!) { | |
| deleteDiscussionComment(input: {id: $id}) { | |
| clientMutationId | |
| } | |
| } | |
| `, { | |
| id: commentId | |
| }).then(() => { | |
| console.log("Deleted a comment containing sensitive words."); | |
| }).catch(error => { | |
| console.error("Error deleting comment:", error); | |
| }); | |
| } else { | |
| console.log("No sensitive words detected."); | |
| } |