Merge with MattJ

Tue, 11 Jan 2011 13:42:07 +0100

author
Kim Alvefur <zash@zash.se>
date
Tue, 11 Jan 2011 13:42:07 +0100
changeset 55
3a321510707c
parent 54
4dcb349bb667 (current diff)
parent 52
0157bfe14958 (diff)
child 56
cb7656ee4dd8

Merge with MattJ

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/bugzilla.lua	Tue Jan 11 13:42:07 2011 +0100
@@ -0,0 +1,58 @@
+
+-- bugzilla plugin - Queries a bugzilla instance, via the !bug command, and responds
+--                   with the data found.
+--                   Requires Bugzilla 3.6 or later, and XMLRPC enabled.
+--                   Also requires lua-xmlrpc - see
+--                     http://keplerproject.github.com/lua-xmlrpc/
+
+-- Configuration:
+--  Define a 'bugzilla' entry pointing to the root of the bugzilla installation,
+-- 			e.g. "http://my.bugzilla.example.com"
+--  Optionally, if the buzgilla requires authentication, define buigzilla_user and
+--  bugzilla_password as well. If they're not defined, it is assumed that authentication
+--  is not required.
+
+-- Written by Ciaran Gultnieks <ciaran@ciarang.com> - feel free to contact if it
+-- doesn't work!
+
+function riddim.plugins.bugzilla(bot)
+
+	local bugzilla = bot.config.bugzilla
+	if not bugzilla then return end
+
+	local bugzilla_x = bugzilla .. "/xmlrpc.cgi"
+
+   require("lxp.lom")
+	xh = require("xmlrpc.http")
+
+	bot:hook("commands/bug", function(command)
+		if not command.param then return end
+		local bug_id = string.match(command.param, "%w+")
+		if not bug_id then return end
+
+		local params = {}
+		if bot.config.bugzilla_user then
+			params.Bugzilla_login = bot.config.bugzilla_user
+			params.Bugzilla_password = bot.config.bugzilla_password
+		end
+		params.permissive = false
+		string_array_type = xmlrpc.newArray ("string")
+		params.ids = xmlrpc.newTypedValue ( { bug_id }, string_array_type)
+
+		local ok,res = xh.call(bugzilla_x, "Bug.get", params)
+		if not ok then
+			command:reply("Failed to get bug details - " .. res)
+			return
+		end
+
+		local bug = res['bugs'][1]
+		local desc = bug.summary
+
+		command:reply(
+			"Bug " .. bug_id .. " (" .. bug.status .. "/" .. bug.resolution
+				.. "): " .. bug.summary .. "  "
+				.. bugzilla .. "/show_bug.cgi?id=" .. bug_id
+			)
+	end)
+end
+

mercurial