Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts[patch]: Add spam comment filter #6633

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/spam-comment-filter.yml
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
1 change: 0 additions & 1 deletion libs/langchain-scripts/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
"*.d.ts",
],
rules: {
"no-process-env": 2,
"no-instanceof/no-instanceof": 2,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0,
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-scripts/bin/filter_spam_comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "../dist/filter_spam_comment.js";
2 changes: 2 additions & 0 deletions libs/langchain-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-scripts/",
"bin": {
"filter_spam_comment": "bin/filter_spam_comment.js",
"lc_build": "bin/build.js",
"notebook_validate": "bin/validate_notebook.js"
},
Expand All @@ -40,6 +41,7 @@
"author": "LangChain",
"license": "MIT",
"dependencies": {
"@octokit/rest": "^21.0.2",
"@rollup/wasm-node": "^4.19.0",
"axios": "^1.6.7",
"commander": "^11.1.0",
Expand Down
51 changes: 51 additions & 0 deletions libs/langchain-scripts/src/filter_spam_comment.ts
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();
123 changes: 123 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12407,6 +12407,7 @@ __metadata:
resolution: "@langchain/scripts@workspace:libs/langchain-scripts"
dependencies:
"@jest/globals": ^29.5.0
"@octokit/rest": ^21.0.2
"@rollup/wasm-node": ^4.19.0
"@swc/core": ^1.3.90
"@swc/jest": ^0.2.29
Expand Down Expand Up @@ -12438,6 +12439,7 @@ __metadata:
tsx: ^4.16.2
typescript: ^5.4.5
bin:
filter_spam_comment: bin/filter_spam_comment.js
lc_build: bin/build.js
notebook_validate: bin/validate_notebook.js
languageName: unknown
Expand Down Expand Up @@ -13096,6 +13098,13 @@ __metadata:
languageName: node
linkType: hard

"@octokit/auth-token@npm:^5.0.0":
version: 5.1.1
resolution: "@octokit/auth-token@npm:5.1.1"
checksum: b39516dda44aeced0326227c53aade621effe1d59c4b0f48ebe2b9fd32b5156e02705bcb2fb1bf48b11f26cc6aff1a0683c32c3d5424e0118dae6596e431d489
languageName: node
linkType: hard

"@octokit/auth-unauthenticated@npm:^5.0.0":
version: 5.0.0
resolution: "@octokit/auth-unauthenticated@npm:5.0.0"
Expand Down Expand Up @@ -13151,6 +13160,31 @@ __metadata:
languageName: node
linkType: hard

"@octokit/core@npm:^6.1.2":
version: 6.1.2
resolution: "@octokit/core@npm:6.1.2"
dependencies:
"@octokit/auth-token": ^5.0.0
"@octokit/graphql": ^8.0.0
"@octokit/request": ^9.0.0
"@octokit/request-error": ^6.0.1
"@octokit/types": ^13.0.0
before-after-hook: ^3.0.2
universal-user-agent: ^7.0.0
checksum: e794fb11b3942f55033f4cf6c0914953fd974587309498e8709c428660fa5c098334d83af5e41457dbe67d92d70a8b559c6cc00457d6c95290fa6c9e1d4bfc42
languageName: node
linkType: hard

"@octokit/endpoint@npm:^10.0.0":
version: 10.1.1
resolution: "@octokit/endpoint@npm:10.1.1"
dependencies:
"@octokit/types": ^13.0.0
universal-user-agent: ^7.0.2
checksum: fde158f40dc9a88e92a8ac1d347a54599aa5715ec24045be9cb8ff8decb3c17b63c91eca1bab12dfe0e0cd37433127dd05cd05db14a719dca749bc56093aa915
languageName: node
linkType: hard

"@octokit/endpoint@npm:^7.0.0":
version: 7.0.6
resolution: "@octokit/endpoint@npm:7.0.6"
Expand Down Expand Up @@ -13216,6 +13250,17 @@ __metadata:
languageName: node
linkType: hard

"@octokit/graphql@npm:^8.0.0":
version: 8.1.1
resolution: "@octokit/graphql@npm:8.1.1"
dependencies:
"@octokit/request": ^9.0.0
"@octokit/types": ^13.0.0
universal-user-agent: ^7.0.0
checksum: 07239666b0ca38a7d8c581570b544ee9fd1a2616c8dd436af31879662b3345c44ed52e3d7b311840a1c5772a23f02caf7585aca56f36e50f38f0207a87577a9c
languageName: node
linkType: hard

"@octokit/oauth-app@npm:^6.0.0":
version: 6.0.0
resolution: "@octokit/oauth-app@npm:6.0.0"
Expand Down Expand Up @@ -13286,6 +13331,17 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-paginate-rest@npm:^11.0.0":
version: 11.3.3
resolution: "@octokit/plugin-paginate-rest@npm:11.3.3"
dependencies:
"@octokit/types": ^13.5.0
peerDependencies:
"@octokit/core": ">=6"
checksum: 93c7993562caed67b67f75aa77ffb10d032c242a70e9380e2fb9ab67dd2fb84d420231d09cd8a64f1553ffd325f3ef8c640c62e4267b7f3b352b16d4d5e11ef6
languageName: node
linkType: hard

"@octokit/plugin-paginate-rest@npm:^6.1.2":
version: 6.1.2
resolution: "@octokit/plugin-paginate-rest@npm:6.1.2"
Expand Down Expand Up @@ -13327,6 +13383,15 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-request-log@npm:^5.3.1":
version: 5.3.1
resolution: "@octokit/plugin-request-log@npm:5.3.1"
peerDependencies:
"@octokit/core": ">=6"
checksum: a27e163282c8d0ba8feee4d3cbbd1b62e1aa89a892877f7a9876fc17ddde3e1e1af922e6664221a0cabae99b8a7a2a5215b9ec2ee5222edb50e06298e99022b0
languageName: node
linkType: hard

"@octokit/plugin-rest-endpoint-methods@npm:13.2.2":
version: 13.2.2
resolution: "@octokit/plugin-rest-endpoint-methods@npm:13.2.2"
Expand All @@ -13338,6 +13403,17 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-rest-endpoint-methods@npm:^13.0.0":
version: 13.2.4
resolution: "@octokit/plugin-rest-endpoint-methods@npm:13.2.4"
dependencies:
"@octokit/types": ^13.5.0
peerDependencies:
"@octokit/core": ">=6"
checksum: 149643bf98933af92003c55ad7f1e87c239941e843708cfc7389d378e85069e88b7cccaf8227469ee037d54da93cbdb881a34ce9888f5a60f89c689305eb5730
languageName: node
linkType: hard

"@octokit/plugin-rest-endpoint-methods@npm:^7.1.2":
version: 7.2.3
resolution: "@octokit/plugin-rest-endpoint-methods@npm:7.2.3"
Expand Down Expand Up @@ -13418,6 +13494,15 @@ __metadata:
languageName: node
linkType: hard

"@octokit/request-error@npm:^6.0.1":
version: 6.1.4
resolution: "@octokit/request-error@npm:6.1.4"
dependencies:
"@octokit/types": ^13.0.0
checksum: e4e475ec50cef8e271f39e69667d0f8eaccb2367aa56b81638c629b5bbfa2b697b40207301e5c797a63051a82d8698e7c792b4050b84e383c54300a49a01304a
languageName: node
linkType: hard

"@octokit/request@npm:^6.0.0":
version: 6.2.8
resolution: "@octokit/request@npm:6.2.8"
Expand Down Expand Up @@ -13457,6 +13542,18 @@ __metadata:
languageName: node
linkType: hard

"@octokit/request@npm:^9.0.0":
version: 9.1.3
resolution: "@octokit/request@npm:9.1.3"
dependencies:
"@octokit/endpoint": ^10.0.0
"@octokit/request-error": ^6.0.1
"@octokit/types": ^13.1.0
universal-user-agent: ^7.0.2
checksum: 0a1c1a4f9ba67954402ef6d1e3d8e78518487750f3a31c100133840fff393ed9cc29533282914adf0731f7cc880a2778b8a6ac81527b376a278360a86e79597d
languageName: node
linkType: hard

"@octokit/rest@npm:19.0.11":
version: 19.0.11
resolution: "@octokit/rest@npm:19.0.11"
Expand All @@ -13481,6 +13578,18 @@ __metadata:
languageName: node
linkType: hard

"@octokit/rest@npm:^21.0.2":
version: 21.0.2
resolution: "@octokit/rest@npm:21.0.2"
dependencies:
"@octokit/core": ^6.1.2
"@octokit/plugin-paginate-rest": ^11.0.0
"@octokit/plugin-request-log": ^5.3.1
"@octokit/plugin-rest-endpoint-methods": ^13.0.0
checksum: 81dc98bbc27d4891a211628ea49ba40f087f986ee85d7e2f0579b66e4046dd6b6d63ffeb0eb011c9240dd61906798795e4b9e309af230f31df0a42db79ae20bc
languageName: node
linkType: hard

"@octokit/tsconfig@npm:^1.0.2":
version: 1.0.2
resolution: "@octokit/tsconfig@npm:1.0.2"
Expand Down Expand Up @@ -21311,6 +21420,13 @@ __metadata:
languageName: node
linkType: hard

"before-after-hook@npm:^3.0.2":
version: 3.0.2
resolution: "before-after-hook@npm:3.0.2"
checksum: 5f76a9d31909f7f1f7125b7e017ff018799308f5c1fc5a5bfeba9986149da77e6a5cdde0d151671cf374a7fa6452533237bb1de62dfd6c235c20e7c61cc9569d
languageName: node
linkType: hard

"better-sqlite3@npm:9.4.0":
version: 9.4.0
resolution: "better-sqlite3@npm:9.4.0"
Expand Down Expand Up @@ -41774,6 +41890,13 @@ __metadata:
languageName: node
linkType: hard

"universal-user-agent@npm:^7.0.0, universal-user-agent@npm:^7.0.2":
version: 7.0.2
resolution: "universal-user-agent@npm:7.0.2"
checksum: 3f02cb6de0bb9fbaf379566bd0320d8e46af6e4358a2e88fce7e70687ed7b48b37f479d728bb22f4204a518e363f3038ac4841c033af1ee2253f6428a6c67e53
languageName: node
linkType: hard

"universalify@npm:^0.2.0":
version: 0.2.0
resolution: "universalify@npm:0.2.0"
Expand Down
Loading