Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/external-contributor-alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,30 @@ jobs:

if (item.draft) { core.info(`Skipping draft PR #${item.number}`); return; }
if (item.user?.type === 'Bot') { core.info(`Skipping bot ${item.user?.login}`); return; }
const INTERNAL = ['OWNER', 'MEMBER', 'COLLABORATOR'];
if (INTERNAL.includes(item.author_association)) {
core.info(`#${item.number} by ${item.user?.login} is internal (${item.author_association}); skipping.`);
const { owner, repo } = context.repo;
// fast path (free): public members & direct collaborators
let internal = ['OWNER', 'MEMBER', 'COLLABORATOR'].includes(item.author_association);
// slow path: catches PRIVATE org members via their granted repo access.
// author_association only reports MEMBER for *public* members, so private
// members would otherwise be misflagged as external. Public repos grant
// everyone implicit 'read', so require triage+ (not permission != 'none').
if (!internal) {
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner, repo, username: item.user.login,
});
const p = data.user?.permissions ?? {};
internal = !!(p.admin || p.maintain || p.push || p.triage);
} catch (e) {
if (e.status !== 404) throw e; // 404 = not a collaborator => external
}
}
if (internal) {
core.info(`#${item.number} by ${item.user?.login} is internal; skipping.`);
return;
}
if (item.labels?.some(l => l.name === LABEL)) { core.info(`#${item.number} already handled.`); return; }

const { owner, repo } = context.repo;
const webhook = process.env.SLACK_WEBHOOK_OSS_PRS;
if (!webhook) {
core.warning('SLACK_WEBHOOK_OSS_PRS not set — no alert sent and not labeled (will retry on next event).');
Expand Down
Loading