diff options
context:
space:
mode:
Diffstat (limited to 'extensions/link-commits.lua')
-rw-r--r--extensions/link-commits.lua27
1 file changed, 27 insertions, 0 deletions
diff --git a/extensions/link-commits.lua b/extensions/link-commits.lua
new file mode 100644
index 0000000..160a12d
--- /dev/null
+++ b/extensions/link-commits.lua
@@ -0,0 +1,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