fix: GitLab pagination load data

This commit is contained in:
Andras Bacsai 2022-07-08 14:36:41 +02:00
parent da11bae67c
commit b105e6fbf8

View File

@ -61,16 +61,7 @@
} catch (error) { } catch (error) {
return await getGitlabToken(); return await getGitlabToken();
} }
try { await loadGroups();
groups = await get(`${apiUrl}/v4/groups?per_page=5000`, {
Authorization: `Bearer ${$appSession.tokens.gitlab}`
});
} catch (error: any) {
errorNotification(error);
throw new Error(error);
} finally {
loading.base = false;
}
}); });
function selectGroup(event: any) { function selectGroup(event: any) {
selected.group = event.detail; selected.group = event.detail;
@ -116,12 +107,34 @@
}, 100); }, 100);
}); });
} }
async function loadGroups(page: number = 1) {
async function loadProjects() { let perPage = 100;
//@ts-ignore //@ts-ignore
const params: any = new URLSearchParams({ const params: any = new URLSearchParams({
page: 1, page,
per_page: 25, per_page: perPage,
});
loading.base = true;
try {
const newGroups = await get(`${apiUrl}/v4/groups?${params}`, {
Authorization: `Bearer ${$appSession.tokens.gitlab}`
});
groups = groups.concat(newGroups);
if (newGroups.length === perPage) {
await loadGroups(page + 1);
}
} catch (error) {
return errorNotification(error);
} finally {
loading.base = false;
}
}
async function loadProjects(page: number = 1) {
let perPage = 100;
//@ts-ignore
const params: any = new URLSearchParams({
page,
per_page: perPage,
archived: false archived: false
}); });
if (search.project) { if (search.project) {
@ -131,9 +144,16 @@
if (username === selected.group.name) { if (username === selected.group.name) {
try { try {
params.append('min_access_level', 40); params.append('min_access_level', 40);
projects = await get(`${apiUrl}/v4/users/${selected.group.name}/projects?${params}`, { const newProjects = await get(
`${apiUrl}/v4/users/${selected.group.name}/projects?${params}`,
{
Authorization: `Bearer ${$appSession.tokens.gitlab}` Authorization: `Bearer ${$appSession.tokens.gitlab}`
}); }
);
projects = projects.concat(newProjects);
if (newProjects.length === perPage) {
await loadProjects(page + 1);
}
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} finally { } finally {
@ -141,9 +161,16 @@
} }
} else { } else {
try { try {
projects = await get(`${apiUrl}/v4/groups/${selected.group.id}/projects?${params}`, { const newProjects = await get(
`${apiUrl}/v4/groups/${selected.group.id}/projects?${params}`,
{
Authorization: `Bearer ${$appSession.tokens.gitlab}` Authorization: `Bearer ${$appSession.tokens.gitlab}`
}); }
);
projects = projects.concat(newProjects);
if (newProjects.length === perPage) {
await loadProjects(page + 1);
}
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} finally { } finally {
@ -163,23 +190,28 @@
selected.branch = event.detail; selected.branch = event.detail;
isBranchAlreadyUsed(); isBranchAlreadyUsed();
} }
async function loadBranches() { async function loadBranches(page: number = 1) {
let perPage = 100;
//@ts-ignore //@ts-ignore
const params = new URLSearchParams({ const params = new URLSearchParams({
page: 1, page,
per_page: 100 per_page: perPage
}); });
if (search.branch) { if (search.branch) {
params.append('search', search.branch); params.append('search', search.branch);
} }
loading.branches = true; loading.branches = true;
try { try {
branches = await get( const newBranches = await get(
`${apiUrl}/v4/projects/${selected.project.id}/repository/branches?${params}`, `${apiUrl}/v4/projects/${selected.project.id}/repository/branches?${params}`,
{ {
Authorization: `Bearer ${$appSession.tokens.gitlab}` Authorization: `Bearer ${$appSession.tokens.gitlab}`
} }
); );
branches = branches.concat(newBranches);
if (newBranches.length === perPage) {
await loadBranches(page + 1);
}
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} finally { } finally {