Skip to content

Commit 6676165

Browse files
committed
[antispam] experimenting (WIP)
1 parent 0e58a31 commit 6676165

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

.github/workflows/scripts/antispam.js

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1+
const configuration = {
2+
label_if_suspicious: false,
3+
comment_if_suspicious: false,
4+
close_if_suspicious: false,
5+
};
6+
7+
async function collect_user_information_report({ user }) {
8+
// we might also create a (pre-)report for spam to GH using the following informations:
9+
return `> [!WARNING] About the author:
10+
>
11+
> | information | value |
12+
> | ----------- | ----- |
13+
> | email | ${user.email} |
14+
> | login | ${user.login} |
15+
> | name | ${user.name} |
16+
> | location | ${user.location} |
17+
> | blog | ${user.blog} |
18+
> | location | ${user.location} |
19+
`
20+
}
21+
122
async function when_suspicious({ github, context, failed_checks }){
223

3-
// might wanna use a score of confidence (how suspicious it is), then react on that
24+
// REFACTO: might wanna use a score of confidence (how suspicious it is), then react on that
425

526
const { owner, repo } = context.repo;
627
const issueNumber = context.payload.number; // either issue or PR
728

8-
// await github.rest.issues.addLabels({
9-
// owner,
10-
// repo,
11-
// issue_number: issueNumber,
12-
// labels: ["suspicious"]
13-
// });
29+
if (! configuration.label_if_suspicious) {
30+
await github.rest.issues.addLabels({
31+
owner,
32+
repo,
33+
issue_number: issueNumber,
34+
labels: ["suspicious"]
35+
});
36+
}
1437

1538
const reasons = failed_checks.map(check => `- ${check.reason}`).join("\n> ");
1639
const commentBody = `> [!WARNING] This issue/PR has been automatically flagged as [suspicious] as it might not meet contribution requirements.
@@ -22,21 +45,23 @@ ${reasons}
2245
`;
2346

2447
console.log("Body of the produced comment:\n", commentBody);
25-
// await github.rest.issues.createComment({
26-
// owner,
27-
// repo,
28-
// issue_number: issueNumber,
29-
// body: `${commentBody}`
30-
// });
31-
32-
// TODO: if too many or critical checks failed, then consider immediatly closing:
33-
34-
// await github.rest.issues.update({
35-
// owner,
36-
// repo,
37-
// issue_number: issueNumber,
38-
// state: "closed"
39-
// });
48+
49+
if (configuration.comment_if_suspicious) {
50+
await github.rest.issues.createComment({
51+
owner,
52+
repo,
53+
issue_number: issueNumber,
54+
body: `${commentBody}`
55+
});
56+
}
57+
if (configuration.close_if_suspicious) {
58+
await github.rest.issues.update({
59+
owner,
60+
repo,
61+
issue_number: issueNumber,
62+
state: "closed"
63+
});
64+
}
4065
}
4166

4267
class Check {
@@ -129,12 +154,6 @@ module.exports = async ({ github, context, core }) => {
129154

130155
when_suspicious({ github, context, failed_checks});
131156

132-
// we might also create a (pre-)report for spam using the following informations:
133-
// user.email
134-
// user.login
135-
// user.name
136-
// user.location
137-
// user.blog
138-
// user.location
139-
// user.email
157+
const user_information_as_comment = collect_user_information_report();
158+
// do stuffs with user_information_as_comment
140159
};

0 commit comments

Comments
 (0)