From f25211cf1ddb86c067ec3c10c8c6d3e5701c7c61 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Fri, 4 Jun 2010 19:48:36 +0200 Subject: Add support for comment ids. Improve error handling in case of invalid bug ids. --- bugzilla.rb | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/bugzilla.rb b/bugzilla.rb index acf6a4a..1b05a47 100644 --- a/bugzilla.rb +++ b/bugzilla.rb @@ -258,7 +258,7 @@ class BugzillaPlugin < Plugin def guess_showbugurl @showbugurl = baseurl @showbugurl += "/" unless baseurl[-1..-1] == "/" - @showbugurl += "show_bug.cgi?id=@BUGNO@" + @showbugurl += "show_bug.cgi?id=@BUGNO@@COMMENT@" end # Guess at the URL for the XML format of any given bug. @@ -327,10 +327,10 @@ class BugzillaPlugin < Plugin end # Return the summary for a given bug. - def summary(bugno) + def summary(bugno, comment="") raise EInvalidInstance.new(self.name, "No XML data URL available") if dataurl == nil - bugdata = REXML::Document.new(@bot.httputil.get(dataurl.gsub("@BUGNO@", bugno))) + bugdata = REXML::Document.new(@bot.httputil.get(dataurl.gsub("@BUGNO@", bugno).gsub("@COMMENT@", ""))) raise EErrorLoading.new(name, bugno) unless bugdata @@ -377,7 +377,8 @@ class BugzillaPlugin < Plugin assignee = shrink_email(assignee) mapping = { - 'BUGNO' => bugno, + 'BUGNO' => bugno, + 'COMMENT' => comment, 'DESC' => desc, 'PRODUCT' => product, 'COMPONENT' => component, @@ -388,7 +389,7 @@ class BugzillaPlugin < Plugin 'STATUS' => status, 'REPORTER' => reporter, 'ASSIGNEE' => assignee, - 'URL' => showbugurl.gsub('@BUGNO@', bugno), + 'URL' => showbugurl.gsub('@BUGNO@', bugno).gsub('@COMMENT@', comment), } output = template.dup mapping.each { |k,v| @@ -532,11 +533,12 @@ class BugzillaPlugin < Plugin def listen(m) return if m.address? return unless lurk?(m) - return if m.message !~ /\bbug(?:[[:space:]]*)?#?([0-9]+)/i + return if m.message !~ /\bbug(?:[[:space:]]*)?#?([0-9]+)(#c[0-9]+)?/i bugno = $1 + comment = $2 || "" bugno.gsub!(/^#/,'') zilla = get_zilla(m) - m.reply zilla.summary(bugno) + m.reply zilla.summary(bugno, comment) end # Function checking when a new channel is joined @@ -558,9 +560,15 @@ class BugzillaPlugin < Plugin # Answer to a bug information request, long form. def buglong(m, params) begin - bugno = params[:number].chomp("#") - bugno.gsub!(/^#/,'') - + if params[:number].chomp("#") =~ /#?([0-9]+)(#c[0-9]+)?/i + bugno = $1 + comment = $2 || "" + bugno.gsub!(/^#/,'') + else + m.reply "Wrong parameters - invalid bugnumber, see 'help bug' for help." + return + end + if params[:zilla] and bugno check_zilla(params[:zilla]) zilla = @zillas[params[:zilla]] @@ -568,7 +576,7 @@ class BugzillaPlugin < Plugin m.reply "Wrong parameters - unknown zilla, see 'help bug' for help." return end - m.reply zilla.summary(bugno) + m.reply zilla.summary(bugno, comment) rescue ::Exception => e m.reply e.message end @@ -577,13 +585,20 @@ class BugzillaPlugin < Plugin # Answer to a bug information request, short form. def bug(m, params) begin - bugno = params[:number].chomp("#") - bugno.gsub!(/^#/,'') + if params[:number].chomp("#") =~ /#?([0-9]+)(#c[0-9]+)?/i + bugno = $1 + comment = $2 ? $2 : "" + bugno.gsub!(/^#/,'') + else + m.reply "Wrong parameters - invalid bugnumber, see 'help bug' for help." + return + end zilla = get_zilla(m) - if not zilla + + if not zilla m.reply "Wrong parameters - unknown zilla, see 'help bug' for help." end - m.reply zilla.summary(bugno) + m.reply zilla.summary(bugno, comment) rescue ::Exception => e m.reply e.message end @@ -601,7 +616,7 @@ class BugzillaPlugin < Plugin m.reply "Wrong parameters (no bugzilla specified), see 'help bugstats' for help." return end - + title = "#{zilla.name.capitalize} bug status totals" # Build our URL -- cgit v1.2.3-18-g5258