mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 20:09:34 +00:00
Previously only org members were allowed. Now checks both org membership and repo collaborator status, so invited collaborators can open issues and PRs without being blocked. Co-authored-by: lab <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
84 lines
2.8 KiB
YAML
84 lines
2.8 KiB
YAML
name: Gate
|
|
|
|
on:
|
|
issues:
|
|
types: [opened]
|
|
pull_request_target:
|
|
types: [opened]
|
|
|
|
permissions:
|
|
issues: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
check-membership:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check org membership and close if external
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
const sender = context.payload.sender.login;
|
|
const { owner, repo } = context.repo;
|
|
|
|
// Check if user is an org member
|
|
let isMember = false;
|
|
try {
|
|
const { status } = await github.rest.orgs.checkMembershipForUser({
|
|
org: owner,
|
|
username: sender,
|
|
});
|
|
isMember = status === 204 || status === 302;
|
|
} catch (e) {
|
|
isMember = false;
|
|
}
|
|
|
|
if (isMember) {
|
|
console.log(`${sender} is an org member of ${owner}, allowing.`);
|
|
return;
|
|
}
|
|
|
|
// Check if user is a repo collaborator
|
|
let isCollaborator = false;
|
|
try {
|
|
const { status } = await github.rest.repos.checkCollaborator({
|
|
owner,
|
|
repo,
|
|
username: sender,
|
|
});
|
|
isCollaborator = status === 204;
|
|
} catch (e) {
|
|
isCollaborator = false;
|
|
}
|
|
|
|
if (isCollaborator) {
|
|
console.log(`${sender} is a collaborator on ${owner}/${repo}, allowing.`);
|
|
return;
|
|
}
|
|
|
|
console.log(`${sender} is NOT a member or collaborator, closing.`);
|
|
|
|
if (context.payload.issue) {
|
|
await github.rest.issues.update({
|
|
...context.repo,
|
|
issue_number: context.payload.issue.number,
|
|
state: 'closed',
|
|
});
|
|
await github.rest.issues.createComment({
|
|
...context.repo,
|
|
issue_number: context.payload.issue.number,
|
|
body: 'This repository only accepts issues from organization members and collaborators. Your issue has been closed automatically.',
|
|
});
|
|
} else if (context.payload.pull_request) {
|
|
await github.rest.pulls.update({
|
|
...context.repo,
|
|
pull_number: context.payload.pull_request.number,
|
|
state: 'closed',
|
|
});
|
|
await github.rest.issues.createComment({
|
|
...context.repo,
|
|
issue_number: context.payload.pull_request.number,
|
|
body: 'This repository only accepts pull requests from organization members and collaborators. Your PR has been closed automatically.',
|
|
});
|
|
}
|