Files
granthi-review/src/lib/access.js
T

20 lines
836 B
JavaScript
Raw Normal View History

// Self-healing bot access: new repos wired by the admin default hook 403 the
// bot's status/comment posts because shre-reviewer is not a collaborator yet.
// On a 403 we add the bot as collaborator (write) using the admin-scoped
// token, then retry the original call exactly once.
export async function withCollabRetry(fn, { adminGitea, owner, repo, botUsername, log }) {
try {
return await fn();
} catch (e) {
if (e?.status !== 403) throw e;
if (!adminGitea) {
log?.(`[${owner}/${repo}] 403 from forge and no admin_token configured — cannot self-heal collaborator access`);
throw e;
}
log?.(`[${owner}/${repo}] 403 from forge — adding ${botUsername} as collaborator (write) and retrying once`);
await adminGitea.addCollaborator(owner, repo, botUsername, 'write');
return fn();
}
}