diff options
author | HampusM <hampus@hampusmat.com> | 2021-06-22 13:31:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-06-22 13:31:43 +0200 |
commit | 43faf0bfd5544f9338e1442ab5b1fcb3210867ac (patch) | |
tree | 98ef97249f6a927b1cfba41b8a3587fd211a68e1 /packages/server/src/api/v1/repo/branches.ts | |
parent | e59d40c2b662a570f679c133a7fe26d1b47edd89 (diff) |
Refactored the backend yet again & got eslint too work with typescript
Diffstat (limited to 'packages/server/src/api/v1/repo/branches.ts')
-rw-r--r-- | packages/server/src/api/v1/repo/branches.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/server/src/api/v1/repo/branches.ts b/packages/server/src/api/v1/repo/branches.ts new file mode 100644 index 0000000..fd8056a --- /dev/null +++ b/packages/server/src/api/v1/repo/branches.ts @@ -0,0 +1,40 @@ +import { FastifyInstance, FastifyPluginOptions } from "fastify"; +import { GitAPI } from "../../git"; +import { Route } from "../../../fastify_types"; +import { verifySHA } from "../../util"; + +export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: (err?: Error) => void): void { + const git: GitAPI = opts.config.git; + + fastify.route<Route>({ + method: "GET", + url: "/branches", + handler: async(req, reply) => { + const branches = await git.getBranches(req.params.repo); + + reply.send({ data: branches }); + } + }); + + fastify.route<Route>({ + method: "GET", + url: "/branches/:branch", + handler: async(req, reply) => { + const branch_verification = await verifySHA(git, req.params.repo, req.params.branch); + if(branch_verification.success === false && branch_verification.code) { + reply.code(branch_verification.code).send({ error: branch_verification.message }); + } + + const branch = await git.getBranch(req.params.repo, req.params.branch); + + if(!branch) { + reply.code(404).send({ error: "Branch not found!" }); + return; + } + + reply.send({ data: branch }); + } + }); + + done(); +}
\ No newline at end of file |