close-external-prs.yml 1.5 KB

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