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 is org member
  14. uses: actions/github-script@v7
  15. with:
  16. script: |
  17. const org = 'anthropics';
  18. const author = context.payload.pull_request.user.login;
  19. try {
  20. await github.rest.orgs.checkMembershipForUser({
  21. org: org,
  22. username: author
  23. });
  24. console.log(`${author} is an org member, allowing PR`);
  25. } catch (e) {
  26. if (e.status === 404) {
  27. await github.rest.issues.createComment({
  28. owner: context.repo.owner,
  29. repo: context.repo.repo,
  30. issue_number: context.payload.pull_request.number,
  31. 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).`
  32. });
  33. await github.rest.pulls.update({
  34. owner: context.repo.owner,
  35. repo: context.repo.repo,
  36. pull_number: context.payload.pull_request.number,
  37. state: 'closed'
  38. });
  39. console.log(`Closed PR from external contributor: ${author}`);
  40. }
  41. }