@@ -44,7 +44,11 @@ import type {
4444 GitlabFetchError ,
4545 GitlabRepository ,
4646} from '../types' ;
47- import { computeTotalCountFromPaginationInfo , handleError } from './utils' ;
47+ import {
48+ computeTotalCountFromPaginationInfo ,
49+ handleError ,
50+ listAllRepositoriesForAuthenticatedUser ,
51+ } from './utils' ;
4852
4953export type ValidatedRepo = {
5054 glConfig : GitLabIntegrationConfig ;
@@ -129,69 +133,32 @@ export async function addGitlabTokenRepositories(
129133 pageSize ?: number ;
130134 } ,
131135) : Promise < { totalCount ?: number } > {
132- const search = reqParams ?. search ;
133- const pageNumber = reqParams ?. pageNumber ?? DefaultPageNumber ;
134- const pageSize = reqParams ?. pageSize ?? DefaultPageSize ;
136+ const lowercaseSearch = reqParams ?. search ?. toLocaleLowerCase ( ) ;
135137 let totalCount : number | undefined ;
136- try {
137- if ( search ) {
138- // Use the projects api with the search param
139- // that api gives us all the things the token has access to including the different projects in various groups
140138
141- const searchResp = await searchRepos (
142- gitlab ,
143- search ,
144- pageNumber ,
145- pageSize ,
146- ) ;
147- totalCount = searchResp . totalCount ;
148- searchResp . repositories . forEach ( repo =>
149- repositories . set ( repo . full_name , repo ) ,
150- ) ;
151- } else {
152- /**
153- * The Projects.all method with the membership: true option will grab all the repositories/projects the gitlab token has explicit access to.
154- * These would include repositories they own, repositories where they are a collaborator,
155- * and repositories that they can access through an organization membership.
156- */
157- const { data, paginationInfo } = await gitlab . Projects . all <
158- true ,
159- 'offset'
160- > ( {
161- membership : true ,
162- perPage : pageSize ,
163- page : pageNumber ,
164- showExpanded : true ,
165- } ) ;
139+ try {
140+ const allRepositories = await listAllRepositoriesForAuthenticatedUser (
141+ deps ,
142+ gitlab ,
143+ ) ;
144+ const filteredRepositories = lowercaseSearch
145+ ? allRepositories . filter ( repo =>
146+ repo . name . toLocaleLowerCase ( ) . includes ( lowercaseSearch ) ,
147+ )
148+ : allRepositories ;
166149
167- data ?. forEach ( ( repo : ProjectSchema ) => {
168- repositories . set ( repo . path_with_namespace , {
169- name : repo . name ,
170- full_name : repo . path_with_namespace ,
171- url : repo . _links . self ,
172- html_url : repo . web_url ,
173- default_branch : repo . default_branch ,
174- updated_at : repo ?. updated_at ,
175- } ) ;
150+ filteredRepositories . forEach ( repo => {
151+ repositories . set ( repo . path_with_namespace , {
152+ name : repo . name ,
153+ full_name : repo . path_with_namespace ,
154+ url : repo . _links . self ,
155+ html_url : repo . web_url ,
156+ default_branch : repo . default_branch ,
157+ updated_at : repo ?. updated_at ,
176158 } ) ;
159+ } ) ;
177160
178- /*
179- paginationInfo: {
180- total: , This is the total amount of repos, but will be NaN if the value is above 10k, see: https://github.com/jdalrymple/gitbeaker/issues/839#issuecomment-636482319
181- next: ,
182- current: ,
183- previous: ,
184- perPage: ,
185- totalPages:
186- }
187- */
188-
189- totalCount = await computeTotalCountFromPaginationInfo (
190- deps ,
191- paginationInfo ,
192- pageSize , // Not thrilled with this for some reason
193- ) ;
194- }
161+ totalCount = filteredRepositories . length ;
195162 } catch ( err ) {
196163 handleError (
197164 deps ,
0 commit comments