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:add("<h2>"..nav(breadcrumb_nav, " / ").."</h2>") |
24 | build:add("<p>"..repo.description.."</p>") |
25 |
|
26 | -- Navigation links |
27 | local navlinks = { |
28 | {string.format("/%s/download", repo.name), "Download"}, |
29 | {string.format("/%s/refs", repo.name), "<b>Refs</b>"}, |
30 | {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, |
31 | {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} |
32 | } |
33 |
|
34 | for _, special in pairs(repo.specialfiles) do -- create nav items for special files |
35 | local split = string.split(special, " ") |
36 | table.insert(navlinks, { |
37 | string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), |
38 | split[1] |
39 | }) |
40 | end |
41 |
|
42 | build:add([[<div class="nav">]]) |
43 | build:add(nav(navlinks)) |
44 | build:add("</div>") |
45 |
|
46 | -- Refs |
47 | local all_refs = git.list_refs(repo_dir) |
48 |
|
49 | -- Branches |
50 | if #all_refs.heads > 0 then |
51 | build:add("<h3>Branches</h3>") |
52 |
|
53 | local branches_table_data = {} |
54 | branches_table_data.class = "branches" |
55 | branches_table_data.headers = { |
56 | {"name", "Name"}, |
57 | {"ref", "Ref"}, |
58 | {"has", "Hash"} |
59 | } |
60 | branches_table_data.rows = {} |
61 |
|
62 | for _, b in pairs(all_refs.heads) do |
63 | table.insert(branches_table_data.rows, { |
64 | b.name ~= branch.name and b.name or b.name.." <b>(HEAD)</b>", |
65 | string.format([[<a href="/%s/tree/%s">%s</a>]], repo.name, b.name, b.full), |
66 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, b.hash, b.shorthash) |
67 | }) |
68 | end |
69 |
|
70 | build:add(tabulate(branches_table_data)) |
71 | end |
72 |
|
73 | -- Tags |
74 | if #all_refs.tags > 0 then |
75 | build:add("<h3>Tags</h3>") |
76 |
|
77 | local tags_table_data = {} |
78 | tags_table_data.class = "tags" |
79 | tags_table_data.headers = { |
80 | {"name", "Name"}, |
81 | {"ref", "Ref"}, |
82 | {"has", "Hash"} |
83 | } |
84 | tags_table_data.rows = {} |
85 | for _, t in pairs(all_refs.tags) do |
86 | table.insert(tags_table_data.rows, { |
87 | t.name ~= branch.name and t.name or t.name.." <b>(HEAD)</b>", |
88 | string.format([[<a href="/%s/tree/%s">%s</a>]], repo.name, t.name, t.full), |
89 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, t.hash, t.shorthash) |
90 | }) |
91 | end |
92 |
|
93 | build:add(tabulate(tags_table_data)) |
94 | end |
95 |
|
96 | return build |
97 | end |
98 |
|
99 | return _M |
100 |
|