-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
54 lines (49 loc) 路 2.36 KB
/
Copy pathbot-prevention.yml
File metadata and controls
54 lines (49 loc) 路 2.36 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
name: Check PR Description
on:
pull_request_target:
types: [opened, reopened]
permissions:
pull-requests: write
jobs:
check-pr-body:
runs-on: ubuntu-latest
steps:
- name: Automatically close modified PR templates
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
if (context.payload.pull_request.user.type === "Bot") {
return;
}
const { data: permissionData } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.pull_request.user.login
});
if (permissionData.permission === "write" || permissionData.permission === "admin") {
return;
}
const requiredTexts = [
"The page(s) are in the correct platform directories: `common`, `linux`, `osx`, `windows`, `sunos`, `android`, etc.",
"The page description(s) have links to documentation or a homepage.",
"The page(s) follow the [content guidelines](/tldr-pages/tldr/blob/main/CONTRIBUTING.md#guidelines).",
"The page(s) follow the [style guide](/tldr-pages/tldr/blob/main/contributing-guides/style-guide.md).",
"The PR contains at most 5 new pages.",
"The PR is authored by me, or has been human-reviewed if it was created with AI or machine translation software.",
"The PR title conforms to the recommended [templates](/tldr-pages/tldr/blob/main/CONTRIBUTING.md#commit-message-and-pr-title)."
]
const body = context.payload.pull_request.body || "";
if (requiredTexts.filter(text => !body.includes(text)).length > 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `This PR was automatically closed due to suspected bot activity.`
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
state: "closed"
});
}