From b59b983da39b8f2bc228bd0acb4bec4b1f954859 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 20 May 2021 19:54:48 +0200 Subject: The function for getting git repos was inproper. So I fixed it. --- api/git.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/api/git.js b/api/git.js index 4eb7fff..8d7fcfe 100644 --- a/api/git.js +++ b/api/git.js @@ -67,30 +67,32 @@ function getRepos(base_dir) { return new Promise((resolve) => { - fs.readdir(base_dir, async (err, dir_content) => + fs.readdir(base_dir, (err, dir_content) => { if(err) { resolve({ "error": err }); return; } - dir_content = dir_content.filter(repo => repo.endsWith(".git")); - - let repos = {}; - - dir_content.forEach(async (repo, index) => + dir_content.filter(repo => repo.endsWith(".git")).reduce((acc, repo) => { - const desc = await getRepoFile(base_dir, repo, "description"); - const owner = await getRepoFile(base_dir, repo, "owner"); - const last_commit_date = await getTimeSinceLatestCommit(base_dir, repo); - - let repo_name = ""; - repo_name = repo.slice(0, -4); - repos[repo_name] = { "description": desc, "owner": owner, "last_updated": last_commit_date }; - - if(index === 0) { - resolve(repos); - } + return acc.then((repos) => + { + return getRepoFile(base_dir, repo, "description").then((description) => + { + return getRepoFile(base_dir, repo, "owner").then((owner) => + { + return getTimeSinceLatestCommit(base_dir, repo).then((last_commit_date) => + { + repos[repo.slice(0, -4)] = { "description": description, "owner": owner, "last_updated": last_commit_date }; + return repos; + }); + }); + }); + }); + }, Promise.resolve({})).then((repos) => + { + resolve(repos); }); }); }); -- cgit v1.2.3-18-g5258