aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-05-20 19:54:48 +0200
committerHampusM <hampus@hampusmat.com>2021-05-20 19:54:48 +0200
commitb59b983da39b8f2bc228bd0acb4bec4b1f954859 (patch)
tree0ea9c491262b853c2e1d42b55ef8cc6b8c7c0058
parent8f64ed8c78df2316b641fba418322c29b88ade45 (diff)
The function for getting git repos was inproper. So I fixed it.
-rw-r--r--api/git.js36
1 files 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);
});
});
});