-
Notifications
You must be signed in to change notification settings - Fork 13
61 lines (53 loc) · 1.75 KB
/
auto-close-pr.yaml
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
name: Auto Close PRs
permissions:
contents: write
pull-requests: write
issues: write
# on:
# pull_request_target:
# types: [opened, reopened]
jobs:
check_pr:
name: Check PR
runs-on: ubuntu-latest
steps:
- name: Check if student
id: check_student
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
try {
const response = await github.rest.orgs.checkMembershipForUser({
org: `github-octernships`,
username: context.payload.pull_request.user.login
});
if (response.status === 204) {
return true;
} else {
return false;
}
} catch (error) {
console.log(error);
return 'false';
}
- name: Close PR
id: close_pr
if: ${{ steps.check_student.outputs.result == 'false' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const body = `This pull request is being automatically closed because we do not accept external contributions to this repository.
Please apply to GitHub Octernships via the [offical page](https://education.github.com/students/octernships)`;
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: body
});
await github.rest.pulls.update({
...context.repo,
pull_number: context.payload.pull_request.number,
state: 'closed'
});