Mon, 06 Dec 2021 11:27:36 +0000
rtbl_admin: Add access control around commands
51 | 1 | |
2 | -- bugzilla plugin - Queries a bugzilla instance, via the !bug command, and responds | |
3 | -- with the data found. | |
4 | -- Requires Bugzilla 3.6 or later, and XMLRPC enabled. | |
5 | -- Also requires lua-xmlrpc - see | |
6 | -- http://keplerproject.github.com/lua-xmlrpc/ | |
7 | ||
8 | -- Configuration: | |
9 | -- Define a 'bugzilla' entry pointing to the root of the bugzilla installation, | |
10 | -- e.g. "http://my.bugzilla.example.com" | |
11 | -- Optionally, if the buzgilla requires authentication, define buigzilla_user and | |
12 | -- bugzilla_password as well. If they're not defined, it is assumed that authentication | |
13 | -- is not required. | |
14 | ||
15 | -- Written by Ciaran Gultnieks <ciaran@ciarang.com> - feel free to contact if it | |
16 | -- doesn't work! | |
17 | ||
18 | function riddim.plugins.bugzilla(bot) | |
19 | ||
20 | local bugzilla = bot.config.bugzilla | |
21 | if not bugzilla then return end | |
22 | ||
23 | local bugzilla_x = bugzilla .. "/xmlrpc.cgi" | |
24 | ||
25 | require("lxp.lom") | |
26 | xh = require("xmlrpc.http") | |
27 | ||
28 | bot:hook("commands/bug", function(command) | |
29 | if not command.param then return end | |
30 | local bug_id = string.match(command.param, "%w+") | |
31 | if not bug_id then return end | |
32 | ||
33 | local params = {} | |
34 | if bot.config.bugzilla_user then | |
35 | params.Bugzilla_login = bot.config.bugzilla_user | |
36 | params.Bugzilla_password = bot.config.bugzilla_password | |
37 | end | |
38 | params.permissive = false | |
39 | string_array_type = xmlrpc.newArray ("string") | |
40 | params.ids = xmlrpc.newTypedValue ( { bug_id }, string_array_type) | |
41 | ||
42 | local ok,res = xh.call(bugzilla_x, "Bug.get", params) | |
43 | if not ok then | |
44 | command:reply("Failed to get bug details - " .. res) | |
45 | return | |
46 | end | |
47 | ||
48 | local bug = res['bugs'][1] | |
49 | local desc = bug.summary | |
50 | ||
51 | command:reply( | |
52 | "Bug " .. bug_id .. " (" .. bug.status .. "/" .. bug.resolution | |
53 | .. "): " .. bug.summary .. " " | |
54 | .. bugzilla .. "/show_bug.cgi?id=" .. bug_id | |
55 | ) | |
56 | end) | |
57 | end | |
58 |