File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Auto Close PRs
2+
3+ on :
4+ pull_request_target :
5+ types : [opened, reopened]
6+
7+ jobs :
8+ check_pr :
9+ name : Check PR
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Check if employee
14+ id : check_employee
15+ uses : actions/github-script@v6
16+ with :
17+ github-token : ${{ secrets.READ_GITHUB_ORG_MEMBERS_TOKEN }}
18+ result-encoding : string
19+ script : |
20+ try {
21+ const response = await github.rest.orgs.checkMembershipForUser({
22+ org: `github`,
23+ username: context.payload.pull_request.user.login
24+ });
25+
26+ if (response.status === 204) {
27+ return true;
28+ } else {
29+ return false;
30+ }
31+ } catch (error) {
32+ console.log(error);
33+ return 'false';
34+ }
35+
36+ - name : Close PR
37+ id : close_pr
38+ if : ${{ steps.check_employee.outputs.result == 'false' }}
39+ uses : actions/github-script@v6
40+ with :
41+ github-token : ${{ secrets.GITHUB_TOKEN }}
42+ script : |
43+ const body = `This pull request is being automatically closed because we do not accept external contributions to this repository.`;
44+
45+ await github.rest.issues.createComment({
46+ ...context.repo,
47+ issue_number: context.issue.number,
48+ body: body
49+ });
50+
51+ await github.rest.pulls.update({
52+ ...context.repo,
53+ pull_number: context.payload.pull_request.number,
54+ state: 'closed'
55+ });
You can’t perform that action at this time.
0 commit comments