1 # Copyright (c) 2005 Diego Pettenò
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies of the Software and its documentation and acknowledgment shall be
12 # given in the documentation and software packages that this Software was
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 def initialize(bughash)
26 @name = bughash["name"]
27 @dataurl = bughash["dataurl"]
28 @reporturl = bughash["reporturl"]
29 @useragent = bughash["useragent"]
33 puts "wgetting #{uri_str}"
34 wget = IO.popen("wget -q -O - '" + uri_str + "'")
41 # OpenOffice's issuezilla is tricky, they call it issue_status
42 status_txt = "bug_status"
46 # doc = OpenURI.open_uri(@dataurl.gsub("${BUGID}", bugno))
47 # bugdata = REXML::Document.new(doc)
48 bugdata = REXML::Document.new(fetch(@dataurl.gsub("${BUGID}", bugno)))
50 return "Unable to load bug # #{bugno}" unless bugdata
52 bugxml = bugdata.root.get_elements("bug")[0]
54 bugxml = bugdata.root.get_elements("issue")[0]
55 status_txt = "issue_status"
58 return "Unable to parse bug # #{bugno}" unless bugxml
60 return "Bug # #{bugno} not found" if bugxml.attribute("status_code").to_s == "404" or
61 bugxml.attribute("error")
63 return "Bug #{bugno}; \"#{bugxml.get_text("short_desc")}\"; #{bugxml.get_text("product")} | #{bugxml.get_text("component")}; #{bugxml.get_text(status_txt)}, #{bugxml.get_text("resolution")}; #{bugxml.get_text("reporter")} -> #{bugxml.get_text("assigned_to")}; #{@reporturl.gsub("${BUGID}", bugno)}"
67 class BugzillaPlugin < Plugin
70 if FileTest.exists?(File.dirname(__FILE__) + "/bugzillas.db")
71 data = File.open(File.dirname(__FILE__) + "/bugzillas.db").read
77 @bugdb = Marshal.load(data)
83 @bugdb.each { |bugzilla|
84 @zillas[bugzilla["name"]] = Bugzilla.new(bugzilla)
90 def help(plugin, topic = "")
93 return "bug <bugzilla> <number> => show the data about given bugzilla's bug."
95 return "addzilla <name> <dataurl> <reporturl> [<useragent>] => add a new bugzilla."
97 return "listzilla => shows the configured bugzillas"
104 unless m.params =~ /^(\w+) #?(\d+)/
105 m.reply "incorrect usage. " + help(m.plugin)
109 bugzilla = $1 # => bugzilla to search for
110 bugno = $2 # => bug number to search for
112 m.reply @zillas[bugzilla].summary(bugno)
114 unless m.params =~ /^(\S+)\s+(\S+)\s+(\S+)(\s+(\S+))?$/
115 m.reply "incorrect usage. " + help(m.plugin)
121 zilla["dataurl"] = $2
122 zilla["reporturl"] = $3
123 zilla["useragent"] = $4 ? $4 : "rBot/#{$version}"
127 Marshal.dump(@bugdb, File.open(File.dirname(__FILE__) + "/bugzillas.db", "w") )
128 @zillas[zilla["name"]] = Bugzilla.new(zilla)
130 m.reply "Added #{zilla["name"]}"
132 m.reply @zillas.keys.join(", ")
137 plugin = BugzillaPlugin.new
138 plugin.register("bug")
139 plugin.register("addzilla")
140 plugin.register("listzilla")
142 ## Kate modeline: leave at the end
143 # kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;