11import * as Sentry from "@sentry/node" ;
2- import { PrismaClient , AccountPermissionSyncJobStatus , Account } from "@sourcebot/db" ;
2+ import { PrismaClient , AccountPermissionSyncJobStatus , Account } from "@sourcebot/db" ;
33import { env , hasEntitlement , createLogger } from "@sourcebot/shared" ;
44import { Job , Queue , Worker } from "bullmq" ;
55import { Redis } from "ioredis" ;
66import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js" ;
7- import { createOctokitFromToken , getReposForAuthenticatedUser } from "../github.js" ;
8- import { createGitLabFromOAuthToken , getProjectsForAuthenticatedUser } from "../gitlab.js" ;
7+ import {
8+ createOctokitFromToken ,
9+ getOAuthScopesForAuthenticatedUser as getGitHubOAuthScopesForAuthenticatedUser ,
10+ getReposForAuthenticatedUser ,
11+ } from "../github.js" ;
12+ import {
13+ createGitLabFromOAuthToken ,
14+ getOAuthScopesForAuthenticatedUser as getGitLabOAuthScopesForAuthenticatedUser ,
15+ getProjectsForAuthenticatedUser ,
16+ } from "../gitlab.js" ;
917import { Settings } from "../types.js" ;
1018import { setIntervalAsync } from "../utils.js" ;
1119
@@ -163,6 +171,12 @@ export class AccountPermissionSyncer {
163171 token : account . access_token ,
164172 url : env . AUTH_EE_GITHUB_BASE_URL ,
165173 } ) ;
174+
175+ const scopes = await getGitHubOAuthScopesForAuthenticatedUser ( octokit ) ;
176+ if ( ! scopes . includes ( 'repo' ) ) {
177+ throw new Error ( `OAuth token with scopes [${ scopes . join ( ', ' ) } ] is missing the 'repo' scope required for permission syncing.` ) ;
178+ }
179+
166180 // @note : we only care about the private repos since we don't need to build a mapping
167181 // for public repos.
168182 // @see : packages/web/src/prisma.ts
@@ -189,6 +203,11 @@ export class AccountPermissionSyncer {
189203 url : env . AUTH_EE_GITLAB_BASE_URL ,
190204 } ) ;
191205
206+ const scopes = await getGitLabOAuthScopesForAuthenticatedUser ( api ) ;
207+ if ( ! scopes . includes ( 'read_api' ) ) {
208+ throw new Error ( `OAuth token with scopes [${ scopes . join ( ', ' ) } ] is missing the 'read_api' scope required for permission syncing.` ) ;
209+ }
210+
192211 // @note : we only care about the private and internal repos since we don't need to build a mapping
193212 // for public repos.
194213 // @see : packages/web/src/prisma.ts
0 commit comments