11import { Client } from "../apiv2" ;
22import { developerConnectOrigin , developerConnectP4SAOrigin } from "../api" ;
33
4- const PAGE_SIZE_MAX = 100 ;
4+ const PAGE_SIZE_MAX = 1000 ;
55
66export const client = new Client ( {
77 urlPrefix : developerConnectOrigin ,
@@ -155,7 +155,10 @@ export async function getConnection(
155155/**
156156 * List Developer Connect Connections
157157 */
158- export async function listConnections ( projectId : string , location : string ) : Promise < Connection [ ] > {
158+ export async function listAllConnections (
159+ projectId : string ,
160+ location : string ,
161+ ) : Promise < Connection [ ] > {
159162 const conns : Connection [ ] = [ ] ;
160163 const getNextPage = async ( pageToken = "" ) : Promise < void > => {
161164 const res = await client . get < {
@@ -181,22 +184,33 @@ export async function listConnections(projectId: string, location: string): Prom
181184/**
182185 * Gets a list of repositories that can be added to the provided Connection.
183186 */
184- export async function fetchLinkableGitRepositories (
187+ export async function listAllLinkableGitRepositories (
185188 projectId : string ,
186189 location : string ,
187190 connectionId : string ,
188- pageToken = "" ,
189- pageSize = 1000 ,
190- ) : Promise < LinkableGitRepositories > {
191+ ) : Promise < LinkableGitRepository [ ] > {
191192 const name = `projects/${ projectId } /locations/${ location } /connections/${ connectionId } :fetchLinkableRepositories` ;
192- const res = await client . get < LinkableGitRepositories > ( name , {
193- queryParams : {
194- pageSize,
195- pageToken,
196- } ,
197- } ) ;
193+ const repos : LinkableGitRepository [ ] = [ ] ;
198194
199- return res . body ;
195+ const getNextPage = async ( pageToken = "" ) : Promise < void > => {
196+ const res = await client . get < LinkableGitRepositories > ( name , {
197+ queryParams : {
198+ PAGE_SIZE_MAX ,
199+ pageToken,
200+ } ,
201+ } ) ;
202+
203+ if ( Array . isArray ( res . body . repositories ) ) {
204+ repos . push ( ...res . body . repositories ) ;
205+ }
206+
207+ if ( res . body . nextPageToken ) {
208+ await getNextPage ( res . body . nextPageToken ) ;
209+ }
210+ } ;
211+
212+ await getNextPage ( ) ;
213+ return repos ;
200214}
201215
202216/**
0 commit comments