From f2d55a9f05f5df7960d7f6dd37d1ef96c762d65a Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 8 Aug 2021 15:33:22 +0200 Subject: Added a tree commit history API endpoint --- packages/server/src/routes/api/v1/repo/index.ts | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'packages/server/src/routes/api/v1/repo/index.ts') diff --git a/packages/server/src/routes/api/v1/repo/index.ts b/packages/server/src/routes/api/v1/repo/index.ts index f5f9030..3b115d4 100644 --- a/packages/server/src/routes/api/v1/repo/index.ts +++ b/packages/server/src/routes/api/v1/repo/index.ts @@ -9,6 +9,7 @@ import log from "./log"; import { verifyRepoName } from "../../util"; import { Tree as APITree, Tag as APITag, TreeEntry as APITreeEntry } from "api"; import { BaseError } from "../../../../git/error"; +import { commitMap } from "./map"; declare module "fastify" { interface FastifyRequest { @@ -99,6 +100,37 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do } }); + fastify.route({ + method: "GET", + url: "/tree/history", + handler: async(req, reply) => { + const tree = await req.repository.tree().catch((err: BaseError) => err); + + if(tree instanceof BaseError) { + reply.code(tree.code).send({ error: tree.message }); + return; + } + + if(Object.keys(req.query).length === 0) { + reply.code(400).send({ error: "Missing query parameter 'path'!" }); + return; + } + + const tree_path = req.query.path; + + const tree_entry = await tree.find(tree_path).catch((err: BaseError) => err); + + if(tree_entry instanceof BaseError) { + reply.code(tree_entry.code).send({ error: tree_entry.message }); + return; + } + + const history = await tree_entry.history(); + + reply.send({ data: await Promise.all(history.map(commitMap)) }); + } + }); + fastify.route({ method: "GET", url: "/tags", @@ -111,4 +143,4 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do }); done(); -} \ No newline at end of file +} -- cgit v1.2.3-18-g5258