From 58763ef84c3a7f548e88abd2aef989deda9c6f23 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Apr 2022 21:48:50 +0200 Subject: [PATCH] fix: Load all branches, not just the first 30 --- .../configuration/_GithubRepositories.svelte | 61 +++++++++++-------- src/tailwind.css | 5 +- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/routes/applications/[id]/configuration/_GithubRepositories.svelte b/src/routes/applications/[id]/configuration/_GithubRepositories.svelte index 06e58be58..81a44018f 100644 --- a/src/routes/applications/[id]/configuration/_GithubRepositories.svelte +++ b/src/routes/applications/[id]/configuration/_GithubRepositories.svelte @@ -36,8 +36,15 @@ }); } + async function loadBranchesByPage(page = 0) { + return await get(`${apiUrl}/repos/${selected.repository}/branches?per_page=100&page=${page}`, { + Authorization: `token ${$gitTokens.githubToken}` + }); + } + let reposSelectOptions; let branchSelectOptions; + async function loadRepositories() { let page = 1; let reposCount = 0; @@ -58,24 +65,27 @@ })); } async function loadBranches(event) { + branches = []; selected.repository = event.detail.value; + let page = 1; + let branchCount = 0; loading.branches = true; - selected.branch = undefined; - selected.projectId = repositories.find((repo) => repo.full_name === selected.repository).id; - try { - branches = await get(`${apiUrl}/repos/${selected.repository}/branches`, { - Authorization: `token ${$gitTokens.githubToken}` - }); - branchSelectOptions = branches.map((branch) => ({ - value: branch.name, - label: branch.name - })); - return; - } catch ({ error }) { - return errorNotification(error); - } finally { - loading.branches = false; + const loadedBranches = await loadBranchesByPage(); + branches = branches.concat(loadedBranches); + branchCount = branches.length; + if (branchCount === 100) { + while (branchCount === 100) { + page = page + 1; + const nextBranches = await loadBranchesByPage(page); + branches = branches.concat(nextBranches); + branchCount = nextBranches.length; + } } + loading.branches = false; + branchSelectOptions = branches.map((branch) => ({ + value: branch.name, + label: branch.name + })); } async function isBranchAlreadyUsed(event) { selected.branch = event.detail.value; @@ -166,30 +176,36 @@ {:else}
-
+