srctree

Gregory Mullen parent f76c4724 145cf9e0
update to verse v0.0.0-1

src/api.zig added: 53, removed: 54, total 0
@@ -46,7 +46,7 @@ const Diff = struct {
};
 
fn diff(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Diff{}, .ok);
return try vrs.sendJSON(.ok, [0]Diff{});
}
 
const HeartBeat = struct {
@@ -54,7 +54,7 @@ const HeartBeat = struct {
};
 
fn heartbeat(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(HeartBeat{ .nice = 69 }, .ok);
return try vrs.sendJSON(.ok, HeartBeat{ .nice = 69 });
}
 
const Issue = struct {
@@ -62,7 +62,7 @@ const Issue = struct {
};
 
fn issue(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Issue{}, .ok);
return try vrs.sendJSON(.ok, [0]Issue{});
}
 
/// Likely to be renamed
@@ -81,7 +81,7 @@ const Network = struct {
};
 
fn network(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(Network{ .networks = [0].{} }, .ok);
return try vrs.sendJSON(.ok, Network{ .networks = [0].{} });
}
 
const Patch = struct {
@@ -89,7 +89,7 @@ const Patch = struct {
};
 
fn patch(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON(Patch{ .patch = [0].{} }, .ok);
return try vrs.sendJSON(.ok, Patch{ .patch = [0].{} });
}
 
const Flex = struct {
@@ -101,7 +101,7 @@ const Flex = struct {
};
 
fn flex(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]Flex{}, .ok);
return try vrs.sendJSON(.ok, [0]Flex{});
}
 
const User = struct {
@@ -110,5 +110,5 @@ const User = struct {
};
 
fn user(vrs: *Verse.Frame) Router.Error!void {
return try vrs.sendJSON([0]User{}, .ok);
return try vrs.sendJSON(.ok, [0]User{});
}
 
src/api/repo.zig added: 53, removed: 54, total 0
@@ -51,12 +51,10 @@ pub fn repo(ctx: *API.Verse.Frame) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.status = .not_found;
return try ctx.sendJSON([0]Repo{}, .ok);
return try ctx.sendJSON(.not_found, [0]Repo{});
},
else => {
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]Repo{}, .ok);
return try ctx.sendJSON(.service_unavailable, [0]Repo{});
},
};
defer gitrepo.raze();
@@ -67,11 +65,11 @@ pub fn repo(ctx: *API.Verse.Frame) API.Router.Error!void {
else => return error.NotImplemented,
};
 
return try ctx.sendJSON([1]Repo{.{
return try ctx.sendJSON(.ok, [1]Repo{.{
.name = req.name,
.head = head.hex[0..],
.updated = "undefined",
}}, .ok);
}});
}
 
pub const RepoBranches = struct {
@@ -90,12 +88,10 @@ pub fn repoBranches(ctx: *API.Verse.Frame) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.status = .not_found;
return try ctx.sendJSON([0]RepoBranches{}, .ok);
return try ctx.sendJSON(.not_found, [0]RepoBranches{});
},
else => {
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]RepoBranches{}, .ok);
return try ctx.sendJSON(.service_unavailable, [0]RepoBranches{});
},
};
defer gitrepo.raze();
@@ -108,11 +104,11 @@ pub fn repoBranches(ctx: *API.Verse.Frame) API.Router.Error!void {
};
}
 
return try ctx.sendJSON([1]RepoBranches{.{
return try ctx.sendJSON(.ok, [1]RepoBranches{.{
.name = req.name,
.updated = "undefined",
.branches = branches[0..],
}}, .ok);
}});
}
 
pub const RepoTags = struct {
@@ -127,30 +123,28 @@ pub fn repoTags(ctx: *API.Verse.Frame) API.Router.Error!void {
var gitrepo = openRepo(ctx.alloc, req.name) catch |err| switch (err) {
error.InvalidName => return error.Abusive,
error.FileNotFound => {
ctx.status = .not_found;
return try ctx.sendJSON([0]RepoTags{}, .ok);
return try ctx.sendJSON(.not_found, [0]RepoTags{});
},
else => {
ctx.status = .service_unavailable;
return try ctx.sendJSON([0]RepoTags{}, .ok);
return try ctx.sendJSON(.service_unavailable, [0]RepoTags{});
},
};
defer gitrepo.raze();
 
const repotags = gitrepo.tags orelse return try ctx.sendJSON([1]RepoTags{.{
const repotags = gitrepo.tags orelse return try ctx.sendJSON(.ok, [1]RepoTags{.{
.name = req.name,
.updated = "undefined",
.tags = &.{},
}}, .ok);
}});
 
const tstack = try ctx.alloc.alloc([]const u8, repotags.len);
 
for (repotags, tstack) |tag, *out| {
out.* = tag.name;
}
return try ctx.sendJSON([1]RepoTags{.{
return try ctx.sendJSON(.ok, [1]RepoTags{.{
.name = req.name,
.updated = "undefined",
.tags = tstack,
}}, .ok);
}});
}
 
src/endpoints/repos/commits.zig added: 53, removed: 54, total 0
@@ -193,7 +193,7 @@ pub fn commitPatch(ctx: *Verse.Frame, sha: []const u8, repo: Git.Repo) Error!voi
//}
ctx.status = .ok;
ctx.headersAdd("Content-Type", "text/x-patch") catch unreachable; // Firefox is trash
ctx.quickStart() catch return Error.Unknown;
ctx.sendHeaders() catch return Error.Unknown;
ctx.sendRawSlice(diff) catch return Error.Unknown;
}
}
 
src/gitweb.zig added: 53, removed: 54, total 0
@@ -134,7 +134,7 @@ fn __objects(ctx: *Verse.Frame) Error!void {
//var data = repo.findBlob(ctx.alloc, &sha) catch unreachable;
 
ctx.status = .ok;
ctx.quickStart() catch return Error.Unknown;
ctx.sendHeaders() catch return Error.Unknown;
ctx.sendRawSlice(data) catch return Error.Unknown;
}
 
 
src/main.zig added: 53, removed: 54, total 0
@@ -172,12 +172,8 @@ pub fn main() !void {
.base = auth.provider(),
};
 
var server = try verse.Server.init(a, .{
var server = try verse.Server.init(a, Srctree.router, .{
.mode = .{ .zwsgi = .{ .file = "./srctree.sock", .chmod = 0o777 } },
.router = .{
.routefn = Srctree.router,
.builderfn = Srctree.builder,
},
.auth = mtls.provider(),
});
 
 
src/srctree.zig added: 53, removed: 54, total 0
@@ -1,11 +1,12 @@
const std = @import("std");
const eql = std.mem.eql;
const Verse = @import("verse");
const Router = Verse.Router;
const Template = Verse.template;
const verse = @import("verse");
const Frame = verse.Frame;
 
const Router = verse.Router;
const Template = verse.template;
const S = Template.Structs;
const Api = @import("api.zig");
//const Types = @import("types.zig");
 
const ROUTE = Router.ROUTE;
const GET = Router.GET;
@@ -43,28 +44,36 @@ pub const routes = [_]Match{
 
const E404Page = Template.PageData("4XX.html");
 
fn notFound(vrs: *Verse.Frame) Router.Error!void {
fn notFound(vrs: *Frame) Router.Error!void {
std.debug.print("404 for route\n", .{});
vrs.status = .not_found;
var page = E404Page.init(.{});
vrs.sendPage(&page) catch unreachable;
}
 
pub fn router(vrs: *Verse.Frame) Router.RoutingError!BuildFn {
// var i_count: usize = 0;
// var itr = Types.Delta.iterator(vrs.alloc, "");
// while (itr.next()) |it| {
// i_count += 1;
// it.raze(vrs.alloc);
// }
pub const router = Router{
.routefn = srouter,
.builderfn = builder,
.routerfn = defaultRouter,
};
 
pub fn srouter(vrs: *Frame) Router.RoutingError!BuildFn {
return Router.router(vrs, &routes);
}
 
fn debug(_: *Verse.Frame) Router.Error!void {
pub fn defaultRouter(frm: *Frame, rt: Router.RouteFn) BuildFn {
return rt(frm) catch |err| switch (err) {
error.MethodNotAllowed => notFound,
error.NotFound => notFound,
error.Unrouteable => notFound,
};
}
 
fn debug(_: *Frame) Router.Error!void {
return error.Abusive;
}
 
pub fn builder(vrs: *Verse.Frame, call: BuildFn) void {
pub fn builder(vrs: *Frame, call: BuildFn) void {
const btns = [1]Template.Structs.NavButtons{.{ .name = "inbox", .extra = 0, .url = "/inbox" }};
var bh: S.BodyHeaderHtml = vrs.response_data.get(S.BodyHeaderHtml) catch .{ .nav = .{
.nav_auth = "Error",