aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/api/v1/repo/branches.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-06-24 22:50:38 +0200
committerHampusM <hampus@hampusmat.com>2021-06-24 22:50:38 +0200
commita13786d6cc185822f5940582efde2349ef729145 (patch)
tree7d4f49b50fc30ced65c5661b22b027456b79948e /packages/server/src/api/v1/repo/branches.ts
parent01e5d215dbc152e34ecd005111171457f87c235d (diff)
Refactored the backend yet again
Diffstat (limited to 'packages/server/src/api/v1/repo/branches.ts')
-rw-r--r--packages/server/src/api/v1/repo/branches.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/server/src/api/v1/repo/branches.ts b/packages/server/src/api/v1/repo/branches.ts
index fd8056a..fe962aa 100644
--- a/packages/server/src/api/v1/repo/branches.ts
+++ b/packages/server/src/api/v1/repo/branches.ts
@@ -1,18 +1,22 @@
import { FastifyInstance, FastifyPluginOptions } from "fastify";
-import { GitAPI } from "../../git";
+import { Branch } from "../../../git/branch";
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 });
+ const branches = await (await req.repository).branches();
+
+ reply.send({
+ data: branches.map(branch => {
+ return {
+ id: branch.id,
+ name: branch.name
+ };
+ })
+ });
}
});
@@ -20,19 +24,20 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do
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);
+ const branch = await Branch.lookup(await req.repository, req.params.branch);
if(!branch) {
reply.code(404).send({ error: "Branch not found!" });
return;
}
- reply.send({ data: branch });
+ reply.send({
+ data: {
+ id: branch.id,
+ name: branch.name,
+ latest_commit: await branch.latestCommit()
+ }
+ });
}
});