1 | -- resty-gitweb@pages/commit.lua |
2 | -- List commit info |
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, commit_hash) |
16 |
|
17 | -- Latest Commit table |
18 | local commit = git.commit(repo_dir, commit_hash) |
19 |
|
20 | local build = builder:new() |
21 |
|
22 | -- Breadcrumb navigation and repository description |
23 | local breadcrumb_nav = { |
24 | {string.format("/%s", repo.name), repo.name}, |
25 | {string.format("/%s/tree/%s", repo.name, commit_hash), commit.shorthash}, |
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, commit_hash), "Commit Log"}, |
37 | {string.format("/%s/tree/%s", repo.name, commit_hash), "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, commit_hash, split[2]), |
44 | split[1] |
45 | }) |
46 | end |
47 |
|
48 | build{ |
49 | build.div{class="nav", nav(navlinks)}, |
50 | build.h3{"Latest Commit"} |
51 | } |
52 |
|
53 | local commits_table_data = {} |
54 | commits_table_data.class = "log" |
55 | commits_table_data.headers = { |
56 | {"count", [[<span class="q" title="Commit number/count">{#}</span>]]}, |
57 | {"timestamp", "Time"}, |
58 | {"shorthash", "Hash"}, |
59 | {"subject", "Subject"}, |
60 | {"author", "Author"}, |
61 | {"changed_files", [[<span class="q" title="# of files changed">#</span>]]}, |
62 | {"changed_plus", [[<span class="q" title="Insertions">(+)</span>]]}, |
63 | {"changed_minus", [[<span class="q" title="Deletions">(-)</span>]]}, |
64 | {"gpggood", [[<span class="q" title="GPG signature status |
65 | |
66 | G: Good (valid) signature |
67 | B: Bad signature |
68 | U: Good signature with unknown validity |
69 | X: Good signature that has expired |
70 | Y: Good signature made by an expired key |
71 | R: Good signature made by a revoked key |
72 | E: Signature can't be checked (e.g. missing key) |
73 | N: No signature">GPG?</span>]]} |
74 | } |
75 | commits_table_data.rows = {} |
76 |
|
77 | table.insert(commits_table_data.rows, { |
78 | git.count(repo_dir, commit.hash), |
79 | utils.iso8601(commit.timestamp), |
80 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, commit.hash, commit.shorthash), |
81 | utils.html_sanitize(commit.subject), |
82 | string.format([[<a href="mailto:%s">%s</a>]], commit.email, utils.html_sanitize(commit.author)), |
83 | commit.diff.num, |
84 | commit.diff.plus, |
85 | commit.diff.minus, |
86 | commit.gpggood |
87 | }) |
88 |
|
89 | build{tabulate(commits_table_data)} |
90 |
|
91 |
|
92 | return build |
93 | end |
94 |
|
95 | return _M |
96 |
|