Skip to content

Commit 6e4e640

Browse files
committed
[antispam] experimenting (WIP)
1 parent cb523d0 commit 6e4e640

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

.github/workflows/antispam.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Anti-Spam Issue & PR Checker
33
on:
44
workflow_dispatch: # manual testing only
55
issues:
6-
types: [opened]
6+
types: [opened, reopened]
77
pull_request:
8-
types: [opened]
8+
types: [opened, reopened]
99

1010
jobs:
1111
check-spam:

.github/workflows/scripts/antispam.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ module.exports = async ({ github, context, core }) => {
6565
username: username,
6666
per_page: 1
6767
});
68-
69-
console.log(">>> is_username_only_contribution_on_GH: ", {
70-
username: username,
71-
events: events,
72-
events_length: events.length,
73-
result: events.length === 0,
74-
});
75-
7668
return events.length === 0;
7769
})();
7870
const WasAuthorRecentlyCreated = (() => {
@@ -87,15 +79,28 @@ module.exports = async ({ github, context, core }) => {
8779
})();
8880

8981
const isTitleOrBodyTooShort = (() => {
82+
83+
if (context.eventName === 'workflow_dispatch') // issues or pull_request
84+
return false;
85+
9086
const payload = context.payload;
9187
const title = payload.issue?.title || payload.pull_request?.title || "";
9288
const body = payload.issue?.body || payload.pull_request?.body || "";
93-
return title.length < 20 || body.length < 20;
94-
})();
9589

96-
console.log(">>> DEBUG", context)
90+
const threshold = 20;
91+
return title.length < threshold
92+
|| body.length < threshold;
93+
})();
9794

9895
const checks = [
96+
new Check({
97+
predicate: () => ! WasAuthorRecentlyCreated,
98+
reason: "Author account was recently created"
99+
}),
100+
new Check({
101+
predicate: () => ! isAuthorOnlyContributionOnGH,
102+
reason: "Author first contribution to any GitHub project"
103+
}),
99104
new Check({
100105
predicate: () => user.followers !== 0 && user.following !== 0,
101106
reason: "Author has no relationships"
@@ -105,16 +110,15 @@ module.exports = async ({ github, context, core }) => {
105110
reason: "Author has no public repo/gist"
106111
}),
107112
new Check({
108-
predicate: () => ! WasAuthorRecentlyCreated,
109-
reason: "Account is less than an hour old"
110-
}),
111-
new Check({
112-
predicate: () => ! isAuthorOnlyContributionOnGH,
113-
reason: "First contribution to any GitHub project"
113+
predicate: () => isTitleOrBodyTooShort,
114+
reason: "Issue/PR title or body too short"
114115
}),
115116
];
116117

117-
// IDEA: use weight instead of booleans
118+
// IDEA: mandatory checks -> if any fails, then reject
119+
// for other checks
120+
// then use a weights/factors instead of booleans,
121+
// compute a confidence score to check against a threshold => if below, then reject
118122
const failed_checks = checks.filter(check => ! check.pass());
119123

120124
const threshold = 0;

0 commit comments

Comments
 (0)