close-external-prs.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. name: Close External PRs
  2. on:
  3. pull_request_target:
  4. types: [opened]
  5. jobs:
  6. check-membership:
  7. if: vars.DISABLE_EXTERNAL_PR_CHECK != 'true'
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Check if author is org member
  11. uses: actions/github-script@v7
  12. with:
  13. script: |
  14. const org = 'anthropics';
  15. const author = context.payload.pull_request.user.login;
  16. try {
  17. await github.rest.orgs.checkMembershipForUser({
  18. org: org,
  19. username: author
  20. });
  21. console.log(`${author} is an org member, allowing PR`);
  22. } catch (e) {
  23. if (e.status === 404) {
  24. await github.rest.issues.createComment({
  25. owner: context.repo.owner,
  26. repo: context.repo.repo,
  27. issue_number: context.payload.pull_request.number,
  28. 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://docs.google.com/forms/d/e/1FAIpQLSdeFthxvjOXUjxg1i3KrOOkEPDJtn71XC-KjmQlxNP63xYydg/viewform).`
  29. });
  30. await github.rest.pulls.update({
  31. owner: context.repo.owner,
  32. repo: context.repo.repo,
  33. pull_number: context.payload.pull_request.number,
  34. state: 'closed'
  35. });
  36. console.log(`Closed PR from external contributor: ${author}`);
  37. }
  38. }