Software /
code /
prosody-modules
Comparison
mod_pubsub_forgejo/test.lua @ 6211:750d64c47ec6 draft
Merge
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Tue, 18 Mar 2025 00:31:36 +0700 |
parent | 6203:131b8bfbefb4 |
comparison
equal
deleted
inserted
replaced
6210:24316a399978 | 6211:750d64c47ec6 |
---|---|
1 -- CLI script to ease templates writing | |
2 -- must be launched with `lua test.lua` after setting the following env vars, | |
3 -- (assuming prosody has been clone in ../../prosody-0.12) | |
4 -- LUA_CPATH=../../prosody-0.12/\?.so | |
5 -- LUA_PATH=../../prosody-0.12/\?.lua\;\?.lua | |
6 -- allow loading ".lib.lua" modules | |
7 local function loadlib(modulename) | |
8 local filename = modulename .. ".lib.lua" | |
9 local file = io.open(filename, "rb") | |
10 if file then | |
11 return load(file:read("a")), modulename | |
12 else | |
13 return filename .. " not found" | |
14 end | |
15 end | |
16 | |
17 table.insert(package.searchers, loadlib) | |
18 | |
19 local json = require "util.json" | |
20 local format = require "format" | |
21 local templates = require "templates" | |
22 | |
23 local function read_json(fname) | |
24 local f = io.open(fname) | |
25 assert(f ~= nil, fname) | |
26 local data = json.decode(f:read("a")) | |
27 f:close() | |
28 return data | |
29 end | |
30 | |
31 local function read_payload(dirname) | |
32 return read_json("./webhook-examples/" .. dirname .. "/content.json") | |
33 end | |
34 | |
35 local function pprint(stanza) print(stanza:indent(1, " "):pretty_print()) end | |
36 | |
37 pprint(format(read_payload("push"), templates.push)) | |
38 pprint(format(read_payload("pull_request"), templates.pull_request)) | |
39 -- pprint(format(read_payload("push_tag"), templates.push)) -- this is a push with 0 commits. It's ugly! | |
40 pprint(format(read_payload("release"), templates.release)) |