Index

resty-gitweb / adbeb10

A git web interface for Lua/OpenResty (you're on it right now!)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
113 Dec 2020 16:16e49d46eInitial commit (imported, read description)Josh Stockin1980G

Blob @ resty-gitweb / pages / refs.lua

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