mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 18:27:19 +00:00
Merge pull request #2966 from Infisical/misc/add-pagination-handling-for-gitlab-groups-fetch
misc: add pagination handling for gitlab groups fetch
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
|
||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
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;
|
const gitLabApiUrl = url ? `${url}/api` : IntegrationUrls.GITLAB_API_URL;
|
||||||
|
|
||||||
let teams: Team[] = [];
|
let teams: Team[] = [];
|
||||||
const res = (
|
let page: number = 1;
|
||||||
await request.get<{ name: string; id: string }[]>(`${gitLabApiUrl}/v4/groups`, {
|
while (page > 0) {
|
||||||
headers: {
|
// eslint-disable-next-line no-await-in-loop
|
||||||
Authorization: `Bearer ${accessToken}`,
|
const { data, headers }: AxiosResponse<{ name: string; id: string }[]> = await request.get(
|
||||||
"Accept-Encoding": "application/json"
|
`${gitLabApiUrl}/v4/groups?page=${page}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
"Accept-Encoding": "application/json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
);
|
||||||
).data;
|
|
||||||
|
|
||||||
teams = res.map((t) => ({
|
page = Number(headers["x-next-page"] ?? "");
|
||||||
name: t.name,
|
teams = teams.concat(
|
||||||
id: t.id.toString()
|
data.map((t) => ({
|
||||||
}));
|
name: t.name,
|
||||||
|
id: t.id.toString()
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return teams;
|
return teams;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user