-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
133 lines (120 loc) · 4.7 KB
/
dmca.yml
File metadata and controls
133 lines (120 loc) · 4.7 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: DMCA Enforcement
on:
issues:
types: [opened, edited, reopened]
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions:
issues: write
pull-requests: write
contents: read
jobs:
dmca-check:
runs-on: ubuntu-latest
steps:
- name: Sparse checkout dmca.json
uses: actions/checkout@v6
with:
sparse-checkout: dmca.json
sparse-checkout-cone-mode: false
- name: Check for DMCA violations
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const dmca = JSON.parse(fs.readFileSync('dmca.json', 'utf-8'));
const blockedServices = dmca.services;
const blockedLower = blockedServices.map(s => s.toLowerCase());
const isPR = !!context.payload.pull_request;
let matched = [];
if (isPR) {
// Check changed file paths for DMCA'd activity folders
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
});
for (const file of files) {
const match = file.filename.match(/^websites\/[A-Z#]\/([^/]+)\//);
if (match) {
const folderName = match[1].toLowerCase();
const idx = blockedLower.indexOf(folderName);
if (idx !== -1) {
matched.push(blockedServices[idx]);
}
}
}
matched = [...new Set(matched)];
} else {
// Check issue title and body for DMCA'd service names
const title = (context.payload.issue.title || '').toLowerCase();
const body = (context.payload.issue.body || '').toLowerCase();
const text = `${title} ${body}`;
for (let i = 0; i < blockedLower.length; i++) {
if (text.includes(blockedLower[i])) {
matched.push(blockedServices[i]);
}
}
}
if (matched.length === 0) {
console.log('No DMCA violations found.');
return;
}
const serviceList = matched.map(s => `- ${s}`).join('\n');
const comment = [
`This ${isPR ? 'pull request' : 'issue'} references activities that have been removed due to a DMCA takedown:`,
'',
serviceList,
'',
`These activities cannot be re-added or modified. This ${isPR ? 'pull request' : 'issue'} has been automatically closed.`,
].join('\n');
if (isPR) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: comment,
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
state: 'closed',
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['dmca'],
});
} catch (e) {
console.log('Could not add label:', e.message);
}
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: comment,
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
state: 'closed',
state_reason: 'not_planned',
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: ['dmca'],
});
} catch (e) {
console.log('Could not add label:', e.message);
}
}
console.log(`Closed ${isPR ? 'PR' : 'issue'} for DMCA violation: ${matched.join(', ')}`);