Skip to content

Commit 6343bb3

Browse files
committed
[antispam] experimenting (WIP)
1 parent a733fac commit 6343bb3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

.github/workflows/scripts/antispam.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ async function run({ github, context }) {
8888

8989
const username = context.actor;
9090
const { data: user } = await github.rest.users.getByUsername({ username: username });
91+
9192
const payload = context.payload;
92-
const title = payload.issue?.title || payload.pull_request?.title || "";
93-
const body = payload.issue?.body || payload.pull_request?.body || "";
9493

95-
console.log('Checking', { user: username, title: title })
94+
const issue_or_pr = (() => {
95+
if (payload.issue) return payload.issue;
96+
if (payload.pull_request) return payload.pull_request;
97+
throw new Error("Only supports issues and PRs")
98+
})();
99+
100+
101+
console.log('Checking', { user: username, title: issue_or_pr.title })
96102

97103
const isAuthorOnlyContributionOnGH = await (async () => {
98104
// WARNING: Depending on the time of day, event latency can be anywhere from 30s to 6h. (source: https://octokit.github.io/rest.js/v21/)
@@ -105,7 +111,7 @@ async function run({ github, context }) {
105111
const WasAuthorRecentlyCreated = (() => {
106112

107113
const time_point = (() => {
108-
let value = new Date();
114+
let value = Date.parse(issue_or_pr.created_at); //new Date();
109115
value.setHours(value.getHours() - 2);
110116
return value;
111117
})();
@@ -118,8 +124,8 @@ async function run({ github, context }) {
118124
return false;
119125

120126
const threshold = 20;
121-
return title.length < threshold
122-
|| body.length < threshold;
127+
return issue_or_pr.length < threshold
128+
|| issue_or_pr.length < threshold;
123129
})();
124130

125131
const checks = [
@@ -226,6 +232,7 @@ class Testing {
226232
const payload_content = {
227233
title: response.data.title,
228234
body: response.data.body,
235+
created_at: new Date() // now
229236
};
230237
return {
231238
actor: response.data.user.login,

0 commit comments

Comments
 (0)