plugins/bugzilla.lua

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