Updated title #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); |