blob: 160a12d87ee705122108d79f666044de6460a104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Turns object hashes and issue references in commit messages into links.
-- Use it with the commit-filter or repo.commit-filter setting and the lua:
-- prefix. cgit hands the filter the message already HTML-escaped, so this
-- only wraps matches in anchors.

local buffer

function filter_open(...)
	buffer = ""
end

function filter_write(str)
	buffer = buffer .. str
end

function filter_close()
	-- Link a 7 to 64 character object name to this repository.
	local out = buffer:gsub("%f[%w](%x+)%f[%W]", function(hex)
		if #hex >= 7 and #hex <= 64 then
			return '<a href="./?id=' .. hex .. '">' .. hex .. '</a>'
		end
	end)
	-- Link "#123" to a bug tracker. Point this at your own.
	out = out:gsub("#(%d+)", '<a href="https://bugs.example.com/?bug=%1">#%1</a>')
	html(out)
	return 0
end