-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (52 loc) · 2.05 KB
/
spam.yml
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
name: Spam Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
check:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
const pull_request = context.payload.pull_request;
if (pull_request === undefined) {
console.log("This is not a pull request");
return;
}
const prOpener = pull_request.user.login;
const { data: contributions } = await github.rest.repos.listContributors({
owner: context.repo.owner,
repo: context.repo.repo,
});
const prOpenerContributions = contributions.find(
(contributor) => contributor.login === prOpener
);
if (
prOpenerContributions !== undefined &&
prOpenerContributions.contributions > 0
) {
console.log("the PR opener has previous contributions");
return;
}
// If the PR opener is not a contributor, check if the body is empty or it contains the default message
const body = pull_request.body;
const defaultMessage = "Explain the rationale behind the changes and remove this line"
if (!body || body.includes(defaultMessage)) {
// Add a comment to the PR
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pull_request.number,
body: "Closing this PR because it does not follow the contribution guidelines.",
});
// Close the PR
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_request.number,
state: "closed",
});
}