mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-18 09:55:19 +00:00
The getGitlabBranches function was only returning the first 20 branches
due to GitLab's default API pagination limit. This prevented users from accessing branches in repositories with more than 20 branches. Changes: - Add pagination loop to fetch all branches across multiple pages - Set per_page to 100 (GitLab's maximum) for efficiency - Add safety check using x-total header to prevent unnecessary requests - Follow the same pagination pattern as validateGitlabProvider function Fixes issue where branch selection was limited to first 20 branches in repositories with many branches.
This commit is contained in:
@@ -303,8 +303,13 @@ export const getGitlabBranches = async (input: {
|
|||||||
|
|
||||||
const gitlabProvider = await findGitlabById(input.gitlabId);
|
const gitlabProvider = await findGitlabById(input.gitlabId);
|
||||||
|
|
||||||
|
const allBranches = [];
|
||||||
|
let page = 1;
|
||||||
|
const perPage = 100; // GitLab's max per page is 100
|
||||||
|
|
||||||
|
while (true) {
|
||||||
const branchesResponse = await fetch(
|
const branchesResponse = await fetch(
|
||||||
`https://gitlab.com/api/v4/projects/${input.id}/repository/branches`,
|
`https://gitlab.com/api/v4/projects/${input.id}/repository/branches?page=${page}&per_page=${perPage}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${gitlabProvider.accessToken}`,
|
Authorization: `Bearer ${gitlabProvider.accessToken}`,
|
||||||
@@ -318,7 +323,21 @@ export const getGitlabBranches = async (input: {
|
|||||||
|
|
||||||
const branches = await branchesResponse.json();
|
const branches = await branchesResponse.json();
|
||||||
|
|
||||||
return branches as {
|
if (branches.length === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
allBranches.push(...branches);
|
||||||
|
page++;
|
||||||
|
|
||||||
|
// Check if we've reached the total using headers (optional optimization)
|
||||||
|
const total = branchesResponse.headers.get("x-total");
|
||||||
|
if (total && allBranches.length >= Number.parseInt(total)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allBranches as {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
commit: {
|
commit: {
|
||||||
|
|||||||
Reference in New Issue
Block a user