Skip to content

Commit f544976

Browse files
committed
[antispam] experimenting (WIP)
1 parent 499a83f commit f544976

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

.github/workflows/scripts/antispam.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ ${reasons}
5050
}
5151

5252
class Check {
53-
constructor(func, reason) {
54-
this.func = func;
53+
constructor({ predicate, reason }) {
54+
this.predicate = predicate;
5555
this.reason = reason;
5656
}
5757

58-
evaluate() { return this.func(); }
58+
evaluate() { return this.predicate(); }
5959
}
6060

6161
module.exports = async ({ github, context, core }) => {
@@ -86,8 +86,8 @@ module.exports = async ({ github, context, core }) => {
8686
const is_author_only_contribution_on_GH = (async () => {
8787
// WARNING: Depending on the time of day, event latency can be anywhere from 30s to 6h. (source: https://octokit.github.io/rest.js/v21/)
8888
const { data: events } = await github.rest.activity.listEventsForAuthenticatedUser({
89-
username: author
90-
// per_page: 1
89+
username: author,
90+
per_page: 1
9191
});
9292

9393
console.log(">>> is_author_only_contribution_on_GH: ", {
@@ -99,15 +99,14 @@ module.exports = async ({ github, context, core }) => {
9999
return events.length === 0;
100100
})();
101101

102-
console.log(">>> context.payload:", context.payload)
103-
104102
const checks = [
105-
new Check(() => was_author_account_recently_created, "Account is less than an hour old"),
106-
new Check(() => is_author_only_contribution_on_GH, "First contribution to any GitHub project"),
107-
new Check(() => user.followers === 0 && user.following === 0, "Author has no relationships"),
108-
new Check(() => user.public_repos === 0 && user.public_gists === 0, "Author has no public reop/gist"),
103+
new Check({ predicate: was_author_account_recently_created, reason: "Account is less than an hour old" }),
104+
new Check({ predicate: is_author_only_contribution_on_GH, reason: "First contribution to any GitHub project" }),
105+
new Check({ predicate: () => user.followers === 0 && user.following === 0, reason: "Author has no relationships" }),
106+
new Check({ predicate: () => user.public_repos === 0 && user.public_gists === 0, reason: "Author has no public reop/gist" }),
109107
];
110108

109+
// IDEA: use weight instead of booleans
111110
const failed_checks = checks.filter(check => check.evaluate());
112111

113112
const threshold = 0;

0 commit comments

Comments
 (0)