Skip to content

Commit 08e79b5

Browse files
Update auto-close-pr.yml
1 parent 23f49ce commit 08e79b5

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

.github/workflows/auto-close-pr.yml

+11-17
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,40 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: Check if employee
14-
id: check_employee
13+
- name: Check if user is a member
14+
id: check_member
1515
uses: actions/github-script@v6
1616
with:
1717
github-token: ${{ secrets.READ_GITHUB_ORG_MEMBERS_TOKEN }}
1818
result-encoding: string
1919
script: |
2020
try {
21-
const response = await github.rest.orgs.checkMembershipForUser({
22-
org: `github`,
21+
const { status } = await github.rest.orgs.checkMembershipForUser({
22+
org: 'github',
2323
username: context.payload.pull_request.user.login
2424
});
25-
26-
if (response.status === 204) {
27-
return true;
28-
} else {
29-
return false;
30-
}
25+
return status === 204 ? 'true' : 'false';
3126
} catch (error) {
32-
console.log(error);
27+
console.error(error);
3328
return 'false';
3429
}
3530
3631
- name: Close PR
37-
id: close_pr
38-
if: ${{ steps.check_employee.outputs.result == 'false' }}
32+
if: steps.check_member.outputs.result == 'false'
3933
uses: actions/github-script@v6
4034
with:
4135
github-token: ${{ secrets.GITHUB_TOKEN }}
4236
script: |
43-
const body = `This pull request is being automatically closed because we do not accept external contributions to this repository.`;
44-
37+
const message = `This pull request has been automatically closed because we do not accept external contributions to this repository.`;
38+
4539
await github.rest.issues.createComment({
4640
...context.repo,
4741
issue_number: context.issue.number,
48-
body: body
42+
body: message
4943
});
5044
5145
await github.rest.pulls.update({
5246
...context.repo,
5347
pull_number: context.payload.pull_request.number,
5448
state: 'closed'
55-
});
49+
});

0 commit comments

Comments
 (0)