-
Notifications
You must be signed in to change notification settings - Fork 361
88 lines (80 loc) · 3.04 KB
/
content-moderation.yml
File metadata and controls
88 lines (80 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Content Moderation
on:
issues:
types: [opened]
pull_request:
types: [opened]
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
jobs:
moderate:
runs-on: ubuntu-latest
if: vars.GH_AW_BLOCKED_USERS != ''
steps:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
env:
BLOCKED_USERS: ${{ vars.GH_AW_BLOCKED_USERS || '' }}
with:
script: |
const blocklist = (process.env.BLOCKED_USERS || '').split(',').map(u => u.trim()).filter(u => u);
core.info(`Blocklist: ${blocklist.join(', ') || 'empty'}`);
if (!blocklist.length) return;
let user, number, commentId;
if (context.eventName === 'issues') {
user = context.payload.issue.user.login;
number = context.payload.issue.number;
} else if (context.eventName === 'pull_request') {
user = context.payload.pull_request.user.login;
number = context.payload.pull_request.number;
} else if (context.eventName === 'issue_comment') {
user = context.payload.comment.user.login;
number = context.payload.issue.number;
commentId = context.payload.comment.id;
}
core.info(`Checking user: ${user}`);
if (!blocklist.includes(user)) {
core.info(`User ${user} not in blocklist, skipping`);
return;
}
core.info(`User ${user} is blocked, taking action`);
if (commentId) {
core.info(`Minimizing comment ${commentId}`);
const comment = await github.rest.issues.getComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId
});
const nodeId = comment.data.node_id;
await github.graphql(
`
mutation($commentId: ID!) {
minimizeComment(input: {subjectId: $commentId, classifier: SPAM}) {
minimizedComment {
isMinimized
}
}
}
`,
{ commentId: nodeId }
);
} else if (context.eventName === 'issues') {
core.info(`Closing issue #${number}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
state: 'closed',
state_reason: 'not_planned'
});
} else if (context.eventName === 'pull_request') {
core.info(`Closing PR #${number}`);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
state: 'closed'
});
}