-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
363 lines (317 loc) · 14.8 KB
/
Copy pathpr.yml
File metadata and controls
363 lines (317 loc) · 14.8 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
name: PR
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize
permissions:
contents: read
pull-requests: write
issues: write
jobs:
label:
name: Label
runs-on: ubuntu-latest
steps:
- name: Check changed paths
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
ci:
- ".github/workflows/*"
- "tests/*"
- "util/*"
- "package.json"
- "package-lock.json"
- "dnsconfig.js"
domain:
- "domains/*"
documentation:
- ".github/PULL_REQUEST_TEMPLATE.md"
- ".github/copilot-instructions.md"
- "README.md"
r-william:
- ".github/CODEOWNERS"
- "TERMS_OF_SERVICE.md"
- "LICENSE"
- name: Check for NS records
id: ns
uses: actions/github-script@v8
env:
DOMAIN_CHANGED: ${{ steps.changes.outputs.domain }}
with:
github-token: ${{ secrets.BOT }}
script: |
if (process.env.DOMAIN_CHANGED !== "true") {
core.setOutput("changed", "false");
return;
}
const files = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
per_page: 100
}
);
const domainFiles = files.filter(
(file) =>
file.filename.startsWith("domains/") &&
file.filename.endsWith(".json") &&
file.status !== "removed"
);
for (const file of domainFiles) {
const { data: content } =
await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: file.filename,
ref: context.payload.pull_request.head.sha
});
const domain = JSON.parse(
Buffer.from(content.content, "base64").toString("utf8")
);
if (
Array.isArray(domain.records?.NS) &&
domain.records.NS.length > 0
) {
core.setOutput("changed", "true");
return;
}
}
core.setOutput("changed", "false");
- name: Comment about NS records
if: steps.ns.outputs.changed == 'true'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.BOT }}
script: |
const marker = "<!-- is-a-dev-bot: ns-record-review -->";
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
);
const alreadyCommented = comments.some(
(comment) =>
comment.user?.login === "is-a-dev-bot" &&
comment.body?.includes(marker)
);
if (!alreadyCommented) {
const body = [
marker,
"## ⚠️ Special review required",
"",
"This pull request contains a request for NS records and will need to be reviewed by the service owner.",
"",
"***Please ensure you have provided reasoning for needing NS records in your PR description, otherwise your request cannot be approved.***",
"",
"---",
"*Do not alert or contact staff about this PR otherwise it will be set to low priority.*"
].join("\n");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ github.event.repository.default_branch }}
- name: Check trusted user
id: check-trusted
continue-on-error: true
env:
PR_AUTHOR_ID: ${{ github.event.pull_request.user.id }}
run: |
node - <<'NODE'
const trustedUsers = require("./util/trusted.json");
const authorId = Number(process.env.PR_AUTHOR_ID);
if (!trustedUsers.some((u) => u.id === authorId)) {
console.log("PR author is not a trusted user.");
process.exit(1);
}
console.log("PR author is a trusted user.");
NODE
- name: Add labels
uses: actions/github-script@v8
env:
CI_CHANGED: ${{ steps.changes.outputs.ci }}
DOCUMENTATION: ${{ steps.changes.outputs.documentation }}
DOMAIN_CHANGED: ${{ steps.changes.outputs.domain }}
NS_CHANGED: ${{ steps.ns.outputs.changed }}
MAINTAINER: ${{ steps.check-trusted.outcome == 'success' }}
R_WILLIAM: ${{ steps.changes.outputs.r-william }}
with:
github-token: ${{ secrets.BOT }}
script: |
const labels = [];
if (process.env.CI_CHANGED === "true") {
labels.push("ci");
}
if (process.env.DOCUMENTATION === "true") {
labels.push("documentation");
}
if (process.env.DOMAIN_CHANGED === "true") {
labels.push("domain");
}
if (process.env.MAINTAINER === "true") {
labels.push("maintainer");
}
if (
process.env.CI_CHANGED === "true" ||
process.env.NS_CHANGED === "true" ||
process.env.R_WILLIAM === "true"
) {
labels.push("r: william");
}
const uniqueLabels = [...new Set(labels)];
if (uniqueLabels.length) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: uniqueLabels
});
}
template:
name: Template
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ github.event.repository.default_branch }}
- name: Validate PR template
id: validate
continue-on-error: true
env:
PR_BODY: ${{ github.event.pull_request.body }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_AUTHOR_ID: ${{ github.event.pull_request.user.id }}
PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
run: node util/check-pr-template.cjs
- name: Handle incomplete PR
if: steps.validate.outcome == 'failure'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.BOT }}
script: |
const label = "reason: incomplete pr";
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label
});
} catch (error) {
throw error;
}
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
if (!labels.data.some((item) => item.name === label)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label]
});
}
const marker = "<!-- is-a-dev-bot: incomplete-pr-template -->";
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
);
const alreadyCommented = comments.some(
(comment) =>
comment.user?.login === "is-a-dev-bot" &&
comment.body?.includes(marker)
);
if (!alreadyCommented) {
const body = [
marker,
"## ❌ Incomplete PR template",
"",
"This pull request is missing required information from the PR template.",
"",
"***Your PR will not be approved without the template being properly filled out!***",
"",
"Please make sure that:",
"",
"- The PR template has not been modified.",
" - *Modifying the PR template will make this check fail.*",
"- All requirement checkboxes are checked.",
" - *All checkboxes must be changed exactly to `[x]`, NOT something like `[ x ]`.*",
"- **Website Preview** is filled out.",
" - *Make sure it is filled between the start/end comment markers.*",
"- **Website Purpose** is filled out.",
" - *Make sure it is filled between the start/end comment markers.*",
"---",
"Once the template has been properly completed, this check will run again automatically."
].join("\n");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}
- name: Remove incomplete label and comment
if: steps.validate.outcome == 'success'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.BOT }}
script: |
const label = "reason: incomplete pr";
const marker = "<!-- is-a-dev-bot: incomplete-pr-template -->";
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
);
for (const comment of comments) {
if (
comment.user?.login === "is-a-dev-bot" &&
comment.body?.includes(marker)
) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id
});
}
}
- name: Fail if PR template is incomplete
if: steps.validate.outcome == 'failure'
run: |
echo "::error::PR template is incomplete."
exit 1