1 | -- resty-gitweb@pages/refs.lua |
2 | -- Refs page builder |
3 |
|
4 | -- Copyright (c) 2020 Joshua 'joshuas3' Stockin |
5 | -- <https://git.joshstock.in/resty-gitweb> |
6 | -- This software is licensed under the MIT License. |
7 |
|
8 | local utils = require("utils/utils") |
9 | local git = require("git/git") |
10 |
|
11 | local builder = require("utils/builder") |
12 | local tabulate = require("utils/tabulate") |
13 | local nav = require("utils/nav") |
14 |
|
15 | local _M = function(repo, repo_dir, branch) |
16 | local build = builder:new() |
17 |
|
18 | -- Breadcrumb navigation and repository description |
19 | local breadcrumb_nav = { |
20 | {string.format("/%s", repo.name), repo.name}, |
21 | {string.format("/%s/refs", repo.name), "refs"}, |
22 | } |
23 | build{ |
24 | build.h2{nav(breadcrumb_nav, " / ")}, |
25 | build.p{repo.description} |
26 | } |
27 |
|
28 | -- Navigation links |
29 | local navlinks = { |
30 | {string.format("/%s/download", repo.name), "Download"}, |
31 | {string.format("/%s/refs", repo.name), "<b>Refs</b>"}, |
32 | {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, |
33 | {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} |
34 | } |
35 |
|
36 | for _, special in pairs(repo.specialfiles) do -- create nav items for special files |
37 | local split = string.split(special, " ") |
38 | table.insert(navlinks, { |
39 | string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), |
40 | split[1] |
41 | }) |
42 | end |
43 |
|
44 | build{ |
45 | build.div{nav(navlinks)} |
46 | } |
47 |
|
48 | -- Refs |
49 | local all_refs = git.list_refs(repo.obj) |
50 |
|
51 | -- Branches |
52 | if #all_refs.heads > 0 then |
53 | build{build.h3{"Branches"}} |
54 |
|
55 | local branches_table_data = {} |
56 | branches_table_data.class = "branches" |
57 | branches_table_data.headers = { |
58 | {"name", "Name"}, |
59 | {"ref", "Ref"}, |
60 | {"has", "Hash"} |
61 | } |
62 | branches_table_data.rows = {} |
63 |
|
64 | for _, b in pairs(all_refs.heads) do |
65 | table.insert(branches_table_data.rows, { |
66 | b.name ~= branch.name and b.name or b.name.." <b>(HEAD)</b>", |
67 | string.format([[<a href="/%s/tree/%s">%s</a>]], repo.name, b.name, b.full), |
68 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, b.hash, b.shorthash) |
69 | }) |
70 | end |
71 |
|
72 | build{tabulate(branches_table_data)} |
73 | end |
74 |
|
75 | -- Tags |
76 | if #all_refs.tags > 0 then |
77 | build{build.h3{"Tags"}} |
78 |
|
79 | local tags_table_data = {} |
80 | tags_table_data.class = "tags" |
81 | tags_table_data.headers = { |
82 | {"name", "Name"}, |
83 | {"ref", "Ref"}, |
84 | {"has", "Hash"} |
85 | } |
86 | tags_table_data.rows = {} |
87 | for _, t in pairs(all_refs.tags) do |
88 | table.insert(tags_table_data.rows, { |
89 | t.name ~= branch.name and t.name or t.name.." <b>(HEAD)</b>", |
90 | string.format([[<a href="/%s/tree/%s">%s</a>]], repo.name, t.name, t.full), |
91 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, t.hash, t.shorthash) |
92 | }) |
93 | end |
94 |
|
95 | build{tabulate(tags_table_data)} |
96 | end |
97 |
|
98 | return build |
99 | end |
100 |
|
101 | return _M |
102 |
|