-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (48 loc) · 1.56 KB
/
auto-close-pr.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
name: Auto Close PRs
on:
pull_request_target:
types: [opened, reopened]
jobs:
check_pr:
name: Check PR
runs-on: ubuntu-latest
steps:
- name: Check if employee
id: check_employee
uses: actions/github-script@v6
with:
github-token: ${{ secrets.READ_KHULNASOFT_ORG_MEMBERS_TOKEN }}
result-encoding: string
script: |
try {
const response = await github.rest.orgs.checkMembershipForUser({
org: `github`,
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_employee.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.`;
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'
});