Skip to content

Commit e0b4ba9

Browse files
committed
[antispam] experimenting (WIP)
1 parent 0459ef4 commit e0b4ba9

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

.github/workflows/antispam.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Anti-Spam Issue & PR Checker
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
pull_request:
7+
types: [opened]
8+
9+
jobs:
10+
check-spam:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/github-script@v7
15+
env:
16+
SHA: '${{env.parentSHA}}'
17+
with:
18+
script: |
19+
const script = require('.github/workflows/scripts/antispam.js')
20+
await script({octokit, context, core})

.github/workflows/scripts/antispam.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
async function when_suspicious(){
2+
3+
// might wanna use a score of confidence (how suspicious it is), then react on that
4+
5+
await octokit.rest.issues.addLabels({
6+
owner,
7+
repo,
8+
issue_number: issueNumber,
9+
labels: ["suspicious"]
10+
});
11+
12+
// await octokit.rest.issues.update({
13+
// owner,
14+
// repo,
15+
// issue_number: issueNumber,
16+
// state: "closed"
17+
// });
18+
// await octokit.rest.issues.createComment({
19+
// owner,
20+
// repo,
21+
// issue_number: issueNumber,
22+
// body: "This issue/PR has been automatically closed as it does not meet our contribution guidelines. Please read our contribution guide before submitting."
23+
// });
24+
}
25+
26+
module.exports = async ({ octokit, context, core }) => {
27+
const {SHA} = process.env;
28+
const author = context.actor;
29+
30+
const { data: user } = await octokit.rest.users.getByUsername({ username: author });
31+
32+
console.log(">>> module: ", {
33+
user: user,
34+
author: author
35+
});
36+
37+
// check if the account was created within the last hour
38+
const is_author_account_recently_created = (() => {
39+
const createdAt = new Date(user.created_at);
40+
const now = new Date();
41+
const accountAgeInMinutes = (now - createdAt) / (1000 * 60);
42+
43+
console.log(">>> is_author_account_recently_created: ", {
44+
now: now,
45+
createdAt: createdAt,
46+
accountAgeInMinutes: accountAgeInMinutes
47+
});
48+
49+
return (accountAgeInMinutes < 60);
50+
})();
51+
52+
const is_author_only_contribution_on_GH = (async () => {
53+
const { data: events } = await github.rest.activity.listEventsForAuthenticatedUser({
54+
username: author,
55+
per_page: 1
56+
});
57+
58+
console.log(">>> is_author_only_contribution_on_GH: ", {
59+
username: author,
60+
events_length: events.length === 0
61+
});
62+
63+
return events.length === 0;
64+
})();
65+
66+
is_author_account_recently_created();
67+
is_author_only_contribution_on_GH();
68+
69+
// when_suspicious();
70+
};

0 commit comments

Comments
 (0)