@@ -24,7 +24,7 @@ import {
2424 type GitLabIntegrationConfig ,
2525} from '@backstage/integration' ;
2626
27- import { Gitlab , OffsetPagination } from '@gitbeaker/rest' ;
27+ import { Gitlab , OffsetPagination , ProjectSchema } from '@gitbeaker/rest' ;
2828
2929import { logErrorIfNeeded } from '../../helpers' ;
3030import type { CustomGitlabCredentialsProvider } from '../GitlabAppManager' ;
@@ -235,3 +235,35 @@ export async function fetchFromAllIntegrations<T>(
235235
236236 return { data, errors : aggregatedErrors } ;
237237}
238+
239+ export async function listAllRepositoriesForAuthenticatedUser (
240+ deps : {
241+ logger : LoggerService ;
242+ } ,
243+ gitlab : InstanceType < typeof Gitlab < false > > ,
244+ options ?: {
245+ pageSize ?: number ;
246+ } ,
247+ ) : Promise < ProjectSchema [ ] > {
248+ try {
249+ /**
250+ * The Projects.all method with the membership: true option will grab all the repositories/projects the gitlab token has explicit access to.
251+ * These would include repositories they own, repositories where they are a collaborator,
252+ * and repositories that they can access through an organization membership.
253+ */
254+ const allProjects = await gitlab . Projects . all < true , 'keyset' > ( {
255+ membership : true ,
256+ perPage : options ?. pageSize ,
257+ showExpanded : true ,
258+ orderBy : 'name' ,
259+ sort : 'asc' ,
260+ } ) ;
261+
262+ return allProjects . data ;
263+ } catch ( error ) {
264+ deps . logger . error (
265+ `Failed to list all repositories for authenticated user: ${ error } ` ,
266+ ) ;
267+ return [ ] ;
268+ }
269+ }
0 commit comments