Skip to content

Commit d6d1e77

Browse files
committed
[antispam] experimenting (WIP)
1 parent 2bff3a7 commit d6d1e77

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

.github/workflows/scripts/antispam.js

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,44 +57,53 @@ module.exports = async ({ github, context, core }) => {
5757

5858
const { data: user } = await github.rest.users.getByUsername({ username: author });
5959

60+
const isAuthorOnlyContributionOnGH = async () => {
61+
// WARNING: Depending on the time of day, event latency can be anywhere from 30s to 6h. (source: https://octokit.github.io/rest.js/v21/)
62+
const { data: events } = await github.rest.activity.listEventsForAuthenticatedUser({
63+
username: author,
64+
per_page: 1
65+
});
66+
67+
console.log(">>> is_author_only_contribution_on_GH: ", {
68+
username: author,
69+
events_length: events.length === 0,
70+
events: events
71+
});
72+
73+
return events.length === 0;
74+
};
75+
const WasAuthorRecentlyCreated = () => {
76+
77+
const time_point = (() => {
78+
let value = new Date();
79+
value.setHours(value.getHours() - 2);
80+
return value;
81+
});
82+
const create_at = new Date(user.created_at);
83+
84+
console.log(">>> was_author_account_recently_created: ", {
85+
time_point: time_point,
86+
create_at: create_at
87+
});
88+
89+
return create_at <= time_point;
90+
}
91+
6092
const checks = [
61-
new Check({ predicate: () => user.followers === 0 && user.following === 0, reason: "Author has no relationships" }),
62-
new Check({ predicate: () => user.public_repos === 0 && user.public_gists === 0, reason: "Author has no public reop/gist" }),
6393
new Check({
64-
predicate: () => {
65-
66-
const time_point = (() => {
67-
let value = new Date();
68-
value.setHours(value.getHours() - 2);
69-
return value;
70-
});
71-
const create_at = new Date(user.created_at);
72-
73-
console.log(">>> was_author_account_recently_created: ", {
74-
time_point: time_point,
75-
create_at: create_at
76-
});
77-
78-
return create_at <= time_point;
79-
},
94+
predicate: () => user.followers === 0 && user.following === 0,
95+
reason: "Author has no relationships"
96+
}),
97+
new Check({
98+
predicate: () => user.public_repos === 0 && user.public_gists === 0,
99+
reason: "Author has no public reop/gist"
100+
}),
101+
new Check({
102+
predicate: WasAuthorRecentlyCreated(),
80103
reason: "Account is less than an hour old"
81104
}),
82105
new Check({
83-
predicate: async () => {
84-
// WARNING: Depending on the time of day, event latency can be anywhere from 30s to 6h. (source: https://octokit.github.io/rest.js/v21/)
85-
const { data: events } = await github.rest.activity.listEventsForAuthenticatedUser({
86-
username: author,
87-
per_page: 1
88-
});
89-
90-
console.log(">>> is_author_only_contribution_on_GH: ", {
91-
username: author,
92-
events_length: events.length === 0,
93-
events: events
94-
});
95-
96-
return events.length === 0;
97-
},
106+
predicate: await isAuthorOnlyContributionOnGH(),
98107
reason: "First contribution to any GitHub project"
99108
}),
100109
];

0 commit comments

Comments
 (0)