close-external-prs.yml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. name: Close External PRs
  2. on:
  3. pull_request_target:
  4. types: [opened]
  5. permissions:
  6. pull-requests: write
  7. issues: write
  8. jobs:
  9. check-membership:
  10. if: vars.DISABLE_EXTERNAL_PR_CHECK != 'true'
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Check if author has write access
  14. uses: actions/github-script@v7
  15. with:
  16. script: |
  17. const author = context.payload.pull_request.user.login;
  18. const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
  19. owner: context.repo.owner,
  20. repo: context.repo.repo,
  21. username: author
  22. });
  23. if (['admin', 'write'].includes(data.permission)) {
  24. console.log(`${author} has ${data.permission} access, allowing PR`);
  25. return;
  26. }
  27. console.log(`${author} has ${data.permission} access, closing PR`);
  28. await github.rest.issues.createComment({
  29. owner: context.repo.owner,
  30. repo: context.repo.repo,
  31. issue_number: context.payload.pull_request.number,
  32. body: `Thanks for your interest! This repo only accepts contributions from Anthropic team members. If you'd like to submit a plugin to the marketplace, please submit your plugin [here](https://clau.de/plugin-directory-submission).`
  33. });
  34. await github.rest.pulls.update({
  35. owner: context.repo.owner,
  36. repo: context.repo.repo,
  37. pull_number: context.payload.pull_request.number,
  38. state: 'closed'
  39. });