Correcting my mistake :) (#17)

Get all user repositorties
This commit is contained in:
Andras Bacsai 2021-04-02 21:36:31 +02:00 committed by GitHub
parent bdbf356910
commit 3af1fd4d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ dist-ssr
.env
yarn-error.log
api/development/console.log
.pnpm-debug.log
.pnpm-debug.log
yarn.lock

View File

@ -18,7 +18,7 @@
let repositories = [];
function dashify(str, options) {
if (typeof str !== "string") return str
if (typeof str !== "string") return str;
return str
.trim()
.replace(/\W/g, m => (/[À-ž]/.test(m) ? m : "-"))
@ -44,6 +44,14 @@
loading.branches = false;
}
async function getGithubRepos(id, page) {
const data = await $fetch(
`https://api.github.com/user/installations/${id}/repositories?per_page=100&page=${page}`,
);
return data;
}
async function loadGithub() {
try {
const { installations } = await $fetch(
@ -55,12 +63,29 @@
$application.github.installation.id = installations[0].id;
$application.github.app.id = installations[0].app_id;
const data = await $fetch(
`https://api.github.com/user/installations/${$application.github.installation.id}/repositories?per_page=10000`,
let page = 1;
let userRepos = 0;
const data = await getGithubRepos(
$application.github.installation.id,
page,
);
repositories = data.repositories;
const foundRepositoryOnGithub = data.repositories.find(
repositories = repositories.concat(data.repositories);
userRepos = data.total_count;
if (userRepos > repositories.length) {
while (userRepos > repositories.length) {
page = page + 1;
const repos = await getGithubRepos(
$application.github.installation.id,
page,
);
repositories = repositories.concat(repos.repositories);
}
}
const foundRepositoryOnGithub = repositories.find(
r =>
r.full_name ===
`${$application.repository.organization}/${$application.repository.name}`,