Sourabh implementation slashdot autoposter #3582
This file contains hidden or 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: Close PRs from Forks | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| - synchronize | |
| jobs: | |
| check-fork: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Check if PR is from a fork | |
| id: check | |
| run: | | |
| echo "PR head repo: ${{ github.event.pull_request.head.repo.full_name }}" | |
| echo "Base repo: ${{ github.event.repository.full_name }}" | |
| if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.event.repository.full_name }}" ]]; then | |
| echo "PR is from a fork" | |
| echo "is_fork=true" >> $GITHUB_ENV | |
| else | |
| echo "PR is not from a fork" | |
| echo "is_fork=false" >> $GITHUB_ENV | |
| fi | |
| - name: Close PR and add comment | |
| if: env.is_fork == 'true' | |
| run: | | |
| PR_NUMBER=${{ github.event.pull_request.number }} | |
| GH_REPO=${{ github.repository }} | |
| echo "Closing PR #$PR_NUMBER in repository $GH_REPO" | |
| gh pr close \ | |
| "$PR_NUMBER" \ | |
| --repo "${{ github.repository }}" \ | |
| --comment "This PR has been closed because PRs from forks are not allowed. Please create a branch directly off the origin repository and resubmit your PR." | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |