|
| 1 | +name: Restrict Issues to Collaborators |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-collaborator: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Check if user is collaborator |
| 12 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 |
| 13 | + with: |
| 14 | + script: | |
| 15 | + const creator = context.payload.issue.user.login; |
| 16 | + const authorAssociation = context.payload.issue.author_association; |
| 17 | +
|
| 18 | + // Allow if user is a collaborator, member, owner, or previous contributor (includes bots) |
| 19 | + const allowedAssociations = ['COLLABORATOR', 'MEMBER', 'OWNER', 'CONTRIBUTOR']; |
| 20 | +
|
| 21 | + if (allowedAssociations.includes(authorAssociation)) { |
| 22 | + console.log(`${creator} has association "${authorAssociation}". Issue allowed.`); |
| 23 | + return; |
| 24 | + } |
| 25 | +
|
| 26 | + // Not authorized - close the issue |
| 27 | + console.log(`${creator} has association "${authorAssociation}". Closing issue.`); |
| 28 | +
|
| 29 | + await github.rest.issues.createComment({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + issue_number: context.issue.number, |
| 33 | + body: `Hi @${creator}! This repository restricts issue creation to WorkOS team members only. ` + |
| 34 | + `If you need to report an issue with our OpenAPI spec, please [contact the WorkOS team directly](https://workos.com/contact).` |
| 35 | + }); |
| 36 | +
|
| 37 | + await github.rest.issues.update({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + issue_number: context.issue.number, |
| 41 | + state: 'closed', |
| 42 | + state_reason: 'not_planned' |
| 43 | + }); |
0 commit comments