forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts[patch]: Add spam comment filter (langchain-ai#6633)
1 parent
e9d36ff
commit 476bde4
Showing
6 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Spam Comment Filter | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
pull_request_review_comment: | ||
types: [created] | ||
|
||
jobs: | ||
filter_spam: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
- name: Build scripts | ||
run: yarn turbo:command build --filter=@langchain/scripts | ||
- name: Run spam detection script | ||
env: | ||
SPAM_COMMENT_GITHUB_TOKEN: ${{ secrets.SPAM_COMMENT_GITHUB_TOKEN }} | ||
COMMENT_JSON: ${{ toJson(github.event.comment) }} | ||
COMMENT_ID: ${{ github.event.comment.id }} | ||
REPO_OWNER: ${{ github.repository_owner }} | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
run: yarn workspace @langchain/scripts filter_spam_comment |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "../dist/filter_spam_comment.js"; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
|
||
async function spamContentFilter() { | ||
if (process.env.SPAM_COMMENT_GITHUB_TOKEN === undefined) { | ||
throw new Error("SPAM_COMMENT_GITHUB_TOKEN is not set"); | ||
} | ||
if (process.env.COMMENT_JSON === undefined) { | ||
throw new Error("COMMENT_JSON is not set"); | ||
} | ||
if (process.env.COMMENT_ID === undefined) { | ||
throw new Error("COMMENT_ID is not set"); | ||
} | ||
if (process.env.REPO_OWNER === undefined) { | ||
throw new Error("REPO_OWNER is not set"); | ||
} | ||
if (process.env.REPO_NAME === undefined) { | ||
throw new Error("REPO_NAME is not set"); | ||
} | ||
|
||
const octokit = new Octokit({ auth: process.env.SPAM_COMMENT_GITHUB_TOKEN }); | ||
|
||
const comment: { body: string } = JSON.parse(process.env.COMMENT_JSON || ""); | ||
const commentId = parseInt(process.env.COMMENT_ID || "", 10); | ||
const owner = process.env.REPO_OWNER || ""; | ||
const repo = process.env.REPO_NAME || ""; | ||
|
||
const SPAM_COMMENT_REGEX = [ | ||
/^download\s+(?:https?:\/\/)?[\w-]+(\.[\w-]+)+[^\s]+\s+password:\s*.+\s+in the installer menu, select\s*.+$/i, | ||
]; | ||
|
||
if ( | ||
SPAM_COMMENT_REGEX.some((pattern) => | ||
pattern.test(comment.body.toLowerCase()) | ||
) | ||
) { | ||
try { | ||
await octokit.rest.issues.deleteComment({ | ||
owner, | ||
repo, | ||
comment_id: commentId, | ||
}); | ||
console.log(`Deleted spam comment with ID: ${commentId}`); | ||
} catch (error) { | ||
console.error("Error deleting comment:", error); | ||
} | ||
} else { | ||
console.log("Comment is not spam"); | ||
} | ||
} | ||
|
||
void spamContentFilter(); |
This file contains 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