# HG changeset patch # User Kim Alvefur # Date 1294749727 -3600 # Node ID 3a321510707cb163e52de46fa5b3d46ada055fc7 # Parent 4dcb349bb66730afc97440f469c45c153d90a0b8# Parent 0157bfe149589f91813d11ece7d60ce340949a9c Merge with MattJ diff -r 4dcb349bb667 -r 3a321510707c plugins/bugzilla.lua --- /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 - 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 +