aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/api/v1.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-06-21 14:12:05 +0200
committerHampusM <hampus@hampusmat.com>2021-06-21 14:12:05 +0200
commit2ceb6e8c986f7e77f0d74aaac065fc969d39fc3e (patch)
tree1706f74d2b88c98fa533f71581e66b4cb46e055b /packages/server/src/api/v1.ts
parentb2cab411ac27e47d5b44f247be7d4323f1550b77 (diff)
Added branch & tag API endpoints, tag tarball downloading and added handlers to the api
Diffstat (limited to 'packages/server/src/api/v1.ts')
-rw-r--r--packages/server/src/api/v1.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/server/src/api/v1.ts b/packages/server/src/api/v1.ts
index e6391a0..b75c473 100644
--- a/packages/server/src/api/v1.ts
+++ b/packages/server/src/api/v1.ts
@@ -6,6 +6,13 @@ import { GitAPI } from "./git";
export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: any) {
const git = new GitAPI(opts.config.settings.base_dir);
+ fastify.setErrorHandler((err, req, reply) => {
+ reply.code(500).send({ error: "Internal server error!" });
+ });
+ fastify.setNotFoundHandler((req, reply) => {
+ reply.code(404).send({ error: "Endpoint not found!" });
+ })
+
fastify.route({
method: "GET",
url: "/info",
@@ -107,6 +114,43 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do
}
});
+ fastify_repo.route({
+ method: "GET",
+ url: "/branches",
+ handler: async(req, reply) => {
+ const params: any = req.params;
+ const branches = await git.getBranches(params.repo);
+
+ reply.send({ data: branches });
+ }
+ });
+
+ fastify_repo.route({
+ method: "GET",
+ url: "/branches/:branch",
+ handler: async(req, reply) => {
+ const params: any = req.params;
+ const branch = await git.getBranch(params.repo, params.branch);
+
+ if(!branch) {
+ reply.code(404).send({ error: "Branch not found!" });
+ return;
+ }
+
+ reply.send({ data: branch });
+ }
+ });
+
+ fastify_repo.route({
+ method: "GET",
+ url: "/tags",
+ handler: async(req, reply) => {
+ const params: any = req.params;
+ const refs = await git.getTags(params.repo);
+ reply.send({ data: refs });
+ }
+ });
+
done_repo();
}, { prefix: "/repos/:repo" });