From d7bfae93b9eeb39786900e22b024b54a678a8c60 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 9 Jun 2021 22:00:41 +0200 Subject: The repository api endpoint includes whether or not the repository has a readme --- packages/server/src/api/git.ts | 12 ++++++++++++ packages/server/src/api/v1.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'packages/server/src') diff --git a/packages/server/src/api/git.ts b/packages/server/src/api/git.ts index 1f39692..9987bcf 100644 --- a/packages/server/src/api/git.ts +++ b/packages/server/src/api/git.ts @@ -392,4 +392,16 @@ export class Git { return false; } } + + async doesReadmeExist(repo_name) { + const full_repo_name = addRepoDirSuffix(repo_name); + const repo = await Repository.openBare(`${this.base_dir}/${full_repo_name}`); + + const master_commit = await repo.getMasterCommit(); + const tree = await master_commit.getTree(); + + const readme = await tree.getEntry("README.md").catch(() => null); + + return Boolean(readme); + } }; \ No newline at end of file diff --git a/packages/server/src/api/v1.ts b/packages/server/src/api/v1.ts index 617e5f1..7aa1f16 100644 --- a/packages/server/src/api/v1.ts +++ b/packages/server/src/api/v1.ts @@ -40,7 +40,7 @@ export default function(fastify: FastifyInstance, opts, done) { const desc = await git.getRepoFile(params.repo, "description"); - reply.send({ data: { name: params.repo, description: desc } }); + reply.send({ data: { name: params.repo, description: desc, has_readme: await git.doesReadmeExist(params.repo) } }); } }); -- cgit v1.2.3-18-g5258