From 612c29225dafbc99918df210c126610083a3a19f Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Fri, 10 Jan 2025 19:06:10 +0800 Subject: [PATCH 1/2] misc: add pagination handling for gitlab groups fetch --- .../integration-auth/integration-team.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/backend/src/services/integration-auth/integration-team.ts b/backend/src/services/integration-auth/integration-team.ts index c39b2c44f..ccbbb72e7 100644 --- a/backend/src/services/integration-auth/integration-team.ts +++ b/backend/src/services/integration-auth/integration-team.ts @@ -1,3 +1,5 @@ +import { AxiosResponse } from "axios"; + import { request } from "@app/lib/config/request"; import { BadRequestError } from "@app/lib/errors"; @@ -11,19 +13,27 @@ const getTeamsGitLab = async ({ url, accessToken }: { url: string; accessToken: const gitLabApiUrl = url ? `${url}/api` : IntegrationUrls.GITLAB_API_URL; let teams: Team[] = []; - const res = ( - await request.get<{ name: string; id: string }[]>(`${gitLabApiUrl}/v4/groups`, { - headers: { - Authorization: `Bearer ${accessToken}`, - "Accept-Encoding": "application/json" + let page: number | undefined = 1; + while (page > 0) { + // eslint-disable-next-line no-await-in-loop + const { data, headers }: AxiosResponse<{ name: string; id: string }[]> = await request.get( + `${gitLabApiUrl}/v4/groups?page=${page}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + "Accept-Encoding": "application/json" + } } - }) - ).data; + ); - teams = res.map((t) => ({ - name: t.name, - id: t.id.toString() - })); + page = Number(headers["x-next-page"]); + teams = teams.concat( + data.map((t) => ({ + name: t.name, + id: t.id.toString() + })) + ); + } return teams; }; From 4bc9bca2879720b80af128dcb4c7505f14429f45 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Fri, 10 Jan 2025 19:08:49 +0800 Subject: [PATCH 2/2] removed undefined type --- backend/src/services/integration-auth/integration-team.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/services/integration-auth/integration-team.ts b/backend/src/services/integration-auth/integration-team.ts index ccbbb72e7..d738625e2 100644 --- a/backend/src/services/integration-auth/integration-team.ts +++ b/backend/src/services/integration-auth/integration-team.ts @@ -13,7 +13,7 @@ const getTeamsGitLab = async ({ url, accessToken }: { url: string; accessToken: const gitLabApiUrl = url ? `${url}/api` : IntegrationUrls.GITLAB_API_URL; let teams: Team[] = []; - let page: number | undefined = 1; + let page: number = 1; while (page > 0) { // eslint-disable-next-line no-await-in-loop const { data, headers }: AxiosResponse<{ name: string; id: string }[]> = await request.get( @@ -26,7 +26,7 @@ const getTeamsGitLab = async ({ url, accessToken }: { url: string; accessToken: } ); - page = Number(headers["x-next-page"]); + page = Number(headers["x-next-page"] ?? ""); teams = teams.concat( data.map((t) => ({ name: t.name,