Index

resty-gitweb / dda0dae

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1224 Jan 2021 17:05dda0daeNew HTML generatorJosh Stockin11010G

Blob @ resty-gitweb / pages / log.lua

text/plain5374 bytesdownload raw
1-- resty-gitweb@pages/log.lua
2-- Log 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
8local utils = require("utils/utils")
9local git = require("git/git")
10
11local builder = require("utils/builder")
12local tabulate = require("utils/tabulate")
13local nav = require("utils/nav")
14
15local _M = function(repo, repo_dir, branch, n, skip)
16 n = tonumber(n or 20)
17 skip = tonumber(skip or 0)
18
19 local build = builder:new()
20
21 -- Breadcrumb navigation and repository description
22 local breadcrumb_nav = {
23 {string.format("/%s", repo.name), repo.name},
24 {string.format("/%s/tree/%s", repo.name, branch.name), branch.name},
25 {string.format("/%s/log/%s", repo.name, branch.name), "log"}
26 }
27 build{
28 build.h2{nav(breadcrumb_nav, " / ")},
29 build.p{repo.description}
30 }
31
32 -- Navigation links
33 local navlinks = {
34 {string.format("/%s/download", repo.name), "Download"},
35 {string.format("/%s/refs", repo.name), "Refs"},
36 {string.format("/%s/log/%s", repo.name, branch.name), "<b>Commit Log</b>"},
37 {string.format("/%s/tree/%s", repo.name, branch.name), "Files"}
38 }
39
40 for _, special in pairs(repo.specialfiles) do -- create nav items for special files
41 local split = string.split(special, " ")
42 table.insert(navlinks, {
43 string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]),
44 split[1]
45 })
46 end
47
48 build{
49 build.div{class="nav", nav(navlinks)},
50 build.h3{"Commits"}
51 }
52
53 -- Commits table
54 local commits_head = git.log(repo_dir, branch.name, path, n, skip, true)
55
56 local this_page = string.format("/%s/log/%s", repo.name, branch.name)
57
58 -- Build controls
59 local controls = [[<div class="controls">]]
60 local prev = false
61 if skip ~= 0 then -- previous page?
62 local params = ""
63 if skip - n > 0 then
64 params = params.."?skip="..tostring(tonumber(skip) - tonumber(n))
65 end
66 if n ~= 20 then
67 if params ~= "" then
68 params = params.."&"
69 else
70 params = params.."?"
71 end
72 params = params.."n="..tostring(n)
73 end
74 controls = controls..[[<span><a href="]]..this_page..params..[[">&lt;&lt; Previous Page</a></span>]]
75 prev = true
76 end
77 if git.count(repo_dir, commits_head[#commits_head].hash) ~= 1 then -- check if last commit in this list is actually the last
78 -- it's not the last, create a "next page" button
79 local params = ""
80 params = params.."?skip="..tostring(skip+n)
81 if n ~= 20 then
82 params = params.."&n="..tostring(n)
83 end
84 if prev then
85 controls = controls..[[<span style="margin:0 5px">|</span>]]
86 end
87 controls = controls..[[<span><a href="]]..this_page..params..[[">Next Page &gt;&gt;</a></span>]]
88 end
89 controls = controls..[[<span float="right">
90 <form class="control-form" method="GET" style="display:inline;margin:0;float:right">
91 <input type="hidden" name="skip" value="]]..tostring(skip)..[[">
92 <label for="n">Results</label>
93 <select id="n" name="n" onchange="if (this.value != 0){this.form.submit();}">
94 <option disabled selected value style="display:none">]]..tostring(n)..[[</option>
95 <option>10</option>
96 <option>20</option>
97 <option>50</option>
98 <option>100</option>
99 </select>
100 </form>
101</span>]]
102 controls = controls.."</div>"
103
104 build{controls}
105
106 -- Build commit table
107 local commits_table_data = {}
108 commits_table_data.class = "log"
109 commits_table_data.headers = {
110 {"count", [[<span class="q" title="Commit number/count">{#}</span>]]},
111 {"timestamp", "Time"},
112 {"shorthash", "Hash"},
113 {"subject", "Subject"},
114 {"author", "Author"},
115 {"changed_files", [[<span class="q" title="# of files changed">#</span>]]},
116 {"changed_plus", [[<span class="q" title="Insertions">(+)</span>]]},
117 {"changed_minus", [[<span class="q" title="Deletions">(-)</span>]]},
118 {"gpggood", [[<span class="q" title="GPG signature status
119
120G: Good (valid) signature
121B: Bad signature
122U: Good signature with unknown validity
123X: Good signature that has expired
124Y: Good signature made by an expired key
125R: Good signature made by a revoked key
126E: Signature can't be checked (e.g. missing key)
127N: No signature">GPG?</span>]]}
128 }
129 commits_table_data.rows = {}
130
131 for i, commit in pairs(commits_head) do
132 table.insert(commits_table_data.rows, {
133 git.count(repo_dir, commit.hash),
134 utils.iso8601(commit.timestamp),
135 string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, commit.hash, commit.shorthash),
136 utils.html_sanitize(commit.subject),
137 string.format([[<a href="mailto:%s">%s</a>]], commit.email, utils.html_sanitize(commit.author)),
138 commit.diff.num,
139 commit.diff.plus,
140 commit.diff.minus,
141 commit.gpggood
142 })
143 end
144
145 -- Add
146 build{tabulate(commits_table_data), controls}
147
148 return build
149end
150
151return _M
152