mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 06:04:43 +00:00
30 lines
911 B
TypeScript
30 lines
911 B
TypeScript
import { getOrCreateOrganization } from "../actors/handles.js";
|
|
import { APP_SHELL_ORGANIZATION_ID } from "../actors/organization/app-shell.js";
|
|
|
|
export interface ResolvedGithubAuth {
|
|
githubToken: string;
|
|
scopes: string[];
|
|
}
|
|
|
|
export async function resolveOrganizationGithubAuth(c: any, organizationId: string): Promise<ResolvedGithubAuth | null> {
|
|
if (!organizationId || organizationId === APP_SHELL_ORGANIZATION_ID) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
const appOrganization = await getOrCreateOrganization(c, APP_SHELL_ORGANIZATION_ID);
|
|
const resolved = await appOrganization.resolveAppGithubToken({
|
|
organizationId: organizationId,
|
|
requireRepoScope: true,
|
|
});
|
|
if (!resolved?.accessToken) {
|
|
return null;
|
|
}
|
|
return {
|
|
githubToken: resolved.accessToken,
|
|
scopes: Array.isArray(resolved.scopes) ? resolved.scopes : [],
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|