Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: add pagination handling for gitlab groups fetch

Sheen Capadngan612c29225daf
diff --git a/backend/src/services/integration-auth/integration-team.ts b/backend/src/services/integration-auth/integration-team.ts
index c39b2c44f5..ccbbb72e7f 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;
};