blob: 17b9eababd1370d29959716d21ff0449c072ea17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
let ( let* ) m f =
let open Lwt.Infix in
m >>= function
| Ok x -> f x
| Error e ->
let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in
Views.error_page msg |> Dream_html.respond
let root _req = Views.root () |> Dream_html.respond
module Repo = struct
let repo_path req = Dream.param req "repo_name"
let summary req =
let* branches = Git_helpers.Branch.all_branches (repo_path req) in
let* commits = Git_helpers.Commit.recent_commits (repo_path req) 10 in
let authors = [ "John Pork"; "Sebastian Jellybean" ] in
Views.Repo.summary (repo_path req) branches commits authors
|> Dream_html.respond
let refs req = Views.Repo.refs (repo_path req) |> Dream_html.respond
let log req = Views.Repo.log (repo_path req) |> Dream_html.respond
let tree req = Views.Repo.tree (repo_path req) |> Dream_html.respond
let commit req =
let id = match Dream.query req "id" with Some id -> id | None -> "" in
let* commit = Git_helpers.Commit.of_id (repo_path req) id in
Views.Repo.commit (repo_path req) commit |> Dream_html.respond
end
let all_handlers =
[
Dream.get "/" root;
Dream.scope "/:repo_name" []
Repo.
[
Dream.get "/" summary;
Dream.get "/refs/" refs;
Dream.get "/log/" log;
Dream.get "/tree/" tree;
Dream.get "/commit/" commit;
];
Dream.get "/static/**" (Dream.static "./lib/static");
]
|