Class: RubyBugzilla
- Inherits:
-
Object
- Object
- RubyBugzilla
- Defined in:
- lib/ruby_bugzilla.rb,
lib/ruby_bugzilla/version.rb
Constant Summary collapse
- CLONE_FIELDS =
[:assigned_to, :cc, :cf_devel_whiteboard, :cf_internal_whiteboard, :component, :groups, :keywords, :op_sys, :platform, :priority, :product, :qa_contact, :severity, :summary, :target_release, :url, :version, :whiteboard, :comments, :description,]
- CMD =
`which bugzilla`.chomp
- COOKIES_FILE =
File.('~/.bugzillacookies')
- VERSION =
"0.5.3"
Instance Attribute Summary collapse
-
#bugzilla_request_hostname ⇒ Object
readonly
Returns the value of attribute bugzilla_request_hostname.
-
#bugzilla_request_uri ⇒ Object
readonly
Returns the value of attribute bugzilla_request_uri.
-
#bugzilla_uri ⇒ Object
Returns the value of attribute bugzilla_uri.
-
#last_command ⇒ Object
Returns the value of attribute last_command.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
-
#xmlrpc ⇒ Object
Returns the value of attribute xmlrpc.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_login! ⇒ Object
-
#clone(bug_id, overrides = {}) ⇒ Fixnum
Clone of an existing bug.
-
#initialize(bugzilla_uri, username, password) ⇒ RubyBugzilla
constructor
A new instance of RubyBugzilla.
- #inspect ⇒ Object
- #installed? ⇒ Boolean
- #login ⇒ Object
-
#modify(bug_ids, options) ⇒ String
Modify an existing bug or set of bugs.
-
#query(options) ⇒ String
Query for existing bugs.
-
#xmlrpc_bug_query(bug_id) ⇒ Fixnum
XMLRPC Bug Query of an existing bug.
Constructor Details
#initialize(bugzilla_uri, username, password) ⇒ RubyBugzilla
Returns a new instance of RubyBugzilla.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_bugzilla.rb', line 29 def initialize(bugzilla_uri, username, password) raise "python-bugzilla not installed" unless installed? raise ArgumentError, "username and password must be set" if username.nil? || password.nil? self.bugzilla_uri = bugzilla_uri self.username = username self.password = password self.xmlrpc = ::XMLRPC::Client.new(bugzilla_request_hostname, '/xmlrpc.cgi', 443, nil, nil, username, password, true, 60) login end |
Instance Attribute Details
#bugzilla_request_hostname ⇒ Object (readonly)
Returns the value of attribute bugzilla_request_hostname.
21 22 23 |
# File 'lib/ruby_bugzilla.rb', line 21 def bugzilla_request_hostname @bugzilla_request_hostname end |
#bugzilla_request_uri ⇒ Object (readonly)
Returns the value of attribute bugzilla_request_uri.
21 22 23 |
# File 'lib/ruby_bugzilla.rb', line 21 def bugzilla_request_uri @bugzilla_request_uri end |
#bugzilla_uri ⇒ Object
Returns the value of attribute bugzilla_uri.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def bugzilla_uri @bugzilla_uri end |
#last_command ⇒ Object
Returns the value of attribute last_command.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def last_command @last_command end |
#password ⇒ Object
Returns the value of attribute password.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def username @username end |
#xmlrpc ⇒ Object
Returns the value of attribute xmlrpc.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def xmlrpc @xmlrpc end |
Class Method Details
.installed? ⇒ Boolean
16 17 18 |
# File 'lib/ruby_bugzilla.rb', line 16 def self.installed? File.exists?(CMD) end |
Instance Method Details
#clear_login! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_bugzilla.rb', line 50 def clear_login! = "HttpOnly_.#{bugzilla_request_hostname}" if File.exists?(COOKIES_FILE) Tempfile.open('ruby_bugzilla') do |out_file| File.read(COOKIES_FILE).each_line do |line| out_file.puts(line) unless line.include?() end out_file.close() FileUtils.mv(out_file.path, COOKIES_FILE) end end end |
#clone(bug_id, overrides = {}) ⇒ Fixnum
Clone of an existing bug
Example:
# Perform a clone of an existing bug, and return the new bug ID.
bz.clone(948970)
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ruby_bugzilla.rb', line 147 def clone(bug_id, overrides={}) raise ArgumentError, "bug_id must be numeric" unless bug_id.to_s =~ /^\d+$/ existing_bz = xmlrpc_bug_query(bug_id) clone_description, clone_comment_is_private = assemble_clone_description(existing_bz) params = {} CLONE_FIELDS.each do |field| next if field == :comments params[field] = existing_bz[field.to_s] end # Apply overrides overrides.each do |param, value| params[param] = value end # Apply base clone fields params[:cf_clone_of] = bug_id params[:description] = clone_description params[:comment_is_private] = clone_comment_is_private execute_xmlrpc('create', params)[:id.to_s] end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/ruby_bugzilla.rb', line 42 def inspect super.gsub(/@password=\".+?\", /, "") end |
#installed? ⇒ Boolean
46 47 48 |
# File 'lib/ruby_bugzilla.rb', line 46 def installed? self.class.installed? end |
#login ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ruby_bugzilla.rb', line 64 def login params = {} params["--debug"] = nil params["login"] = [username, password] begin execute_shell(params) rescue clear_login! # A failed login attempt could result in a corrupt COOKIES_FILE raise end end |
#modify(bug_ids, options) ⇒ String
Modify an existing bug or set of bugs
Examples:
# Set the status of multiple bugs to RELEASE_PENDING
bz.modify([948970, 948971], :status => "RELEASE_PENDING")
# Add a comment
bz.modify("948972", :comment => "whatevs")
# Set the status to POST and add a comment
bz.modify(948970, :status => "POST", :comment => "Fixed in shabla")
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ruby_bugzilla.rb', line 124 def modify(bug_ids, ) bug_ids = Array(bug_ids) raise ArgumentError, "bug_ids and options must be specified" if bug_ids.empty? || .empty? raise ArgumentError, "bug_ids must be numeric" unless bug_ids.all? {|id| id.to_s =~ /^\d+$/ } params = {} params["modify"] = bug_ids (params, ) execute_shell(params) end |
#query(options) ⇒ String
Query for existing bugs
Example:
# Query for all NEW bugs, and return the output in a specific format.
puts bz.query(
:bug_status => "NEW",
:outputformat => "BZ_ID: %{id} STATUS: %{bug_status} SUMMARY: %{summary}"
)
# BZ_ID: 1234 STATUS: NEW SUMMARY: Something went wrong.
# BZ_ID: 1235 STATUS: NEW SUMMARY: Another thing went wrong.
96 97 98 99 100 101 102 103 104 |
# File 'lib/ruby_bugzilla.rb', line 96 def query() raise ArgumentError, "options must be specified" if .empty? params = {} params["query"] = nil (params, ) execute_shell(params) end |
#xmlrpc_bug_query(bug_id) ⇒ Fixnum
XMLRPC Bug Query of an existing bug
Example:
# Perform an xmlrpc query for a single bug.
bz.xmlrpc_bug_query(948970)
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ruby_bugzilla.rb', line 181 def xmlrpc_bug_query(bug_id) raise ArgumentError, "bug_id must be numeric" unless bug_id.to_s =~ /^\d+$/ params = {} params[:Bugzilla_login] = username params[:Bugzilla_password] = password params[:ids] = bug_id params[:include_fields] = CLONE_FIELDS execute_xmlrpc('get', params)['bugs'].last end |