Skip to content

Update auto-close-pr.yml #81

Update auto-close-pr.yml

Update auto-close-pr.yml #81

Workflow file for this run

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 user is a member
id: check_member
uses: actions/github-script@v6
with:
github-token: ${{ secrets.READ_GITHUB_ORG_MEMBERS_TOKEN }}
result-encoding: string
script: |
try {
const { status } = await github.rest.orgs.checkMembershipForUser({
org: 'github',
username: context.payload.pull_request.user.login
});
return status === 204 ? 'true' : 'false';
} catch (error) {
console.error(error);
return 'false';
}
- name: Close PR
if: steps.check_member.outputs.result == 'false'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const message = `This pull request has been 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: message
});
await github.rest.pulls.update({
...context.repo,
pull_number: context.payload.pull_request.number,
state: 'closed'
});