class ActiveBugzilla::Service
Constants
- CLONE_FIELDS
- DEFAULT_CGI_PATH
- DEFAULT_PORT
- DEFAULT_PROXY_HOST
- DEFAULT_PROXY_PORT
- DEFAULT_TIMEOUT
- DEFAULT_USE_SSL
Attributes
Public Class Methods
# File lib/active_bugzilla/service.rb, line 61 def initialize(bugzilla_uri, username, password) raise ArgumentError, "username and password must be set" if username.nil? || password.nil? self.bugzilla_uri = bugzilla_uri self.username = username self.password = password end
# File lib/active_bugzilla/service.rb, line 47 def self.product defined?(@@product) && @@product end
# File lib/active_bugzilla/service.rb, line 43 def self.product=(value) @@product = value end
# File lib/active_bugzilla/service.rb, line 35 def self.timeout defined?(@@timeout) && @@timeout end
# File lib/active_bugzilla/service.rb, line 31 def self.timeout=(value) @@timeout = value end
Public Instance Methods
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#add_comment
# File lib/active_bugzilla/service.rb, line 79 def add_comment(bug_id, comment, params = {}) params[:id] = bug_id params[:comment] = comment execute('add_comment', params)["id"] end
# File lib/active_bugzilla/service.rb, line 55 def bugzilla_uri=(value) @bugzilla_request_uri = URI.join(value, "xmlrpc.cgi").to_s @bugzilla_request_hostname = URI(value).hostname @bugzilla_uri = value end
Clone of an existing bug
Example:
# Perform a clone of an existing bug, and return the new bug ID. bz.clone(948970)
@param bug_id [String, Fixnum] A single bug id to process. @param overrides [Hash] The properties to change from the source bug. Some properties include
* <tt>:target_release</tt> - The target release for the new cloned bug. * <tt>:assigned_to</tt> - The person to assign the new cloned bug to.
@return [Fixnum] The bug id to the new, cloned, bug.
# File lib/active_bugzilla/service.rb, line 143 def clone(bug_id, overrides = {}) raise ArgumentError, "bug_id must be numeric" unless bug_id.to_s =~ /^\d+$/ existing_bz = get(bug_id, :include_fields => CLONE_FIELDS).first 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 create(params)[:id.to_s] end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#comments
# File lib/active_bugzilla/service.rb, line 74 def comments(params = {}) execute('comments', params) end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#create
# File lib/active_bugzilla/service.rb, line 128 def create(params) execute('create', params) end
Bypass python-bugzilla and use the xmlrpc API directly.
# File lib/active_bugzilla/service.rb, line 170 def execute(action, params) cmd = "Bug.#{action}" params[:Bugzilla_login] ||= username params[:Bugzilla_password] ||= password self.last_command = command_string(cmd, params) xmlrpc_client.call(cmd, params) end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#fields
# File lib/active_bugzilla/service.rb, line 86 def fields(params = {}) execute('fields', params)['fields'] end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#get XMLRPC Bug
Query of an existing bug
Example:
# Perform an xmlrpc query for a single bug. bz.get(948970)
@param bug_id [Array, String, Fixnum] One or more bug ids to process. @return [Array] Array of matching bug hashes.
# File lib/active_bugzilla/service.rb, line 99 def get(bug_ids, params = {}) bug_ids = Array(bug_ids) raise ArgumentError, "bug_ids must be all Numeric" unless bug_ids.all? { |id| id.to_s =~ /^\d+$/ } params[:ids] = bug_ids results = execute('get', params)['bugs'] return [] if results.nil? results end
# File lib/active_bugzilla/service.rb, line 69 def inspect super.gsub(/@password=\".+?\", /, "") end
# File lib/active_bugzilla/service.rb, line 51 def product self.class.product end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#search
# File lib/active_bugzilla/service.rb, line 111 def search(params = {}) params[:creation_time] &&= to_xmlrpc_timestamp(params[:creation_time]) params[:last_change_time] &&= to_xmlrpc_timestamp(params[:last_change_time]) params[:product] ||= product if product results = execute('search', params)['bugs'] return [] if results.nil? results end
# File lib/active_bugzilla/service.rb, line 39 def timeout self.class.timeout end
www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html#update
# File lib/active_bugzilla/service.rb, line 122 def update(ids, params = {}) params[:ids] = Array(ids) execute('update', params)['bugs'] end
Private Instance Methods
# File lib/active_bugzilla/service.rb, line 216 def assemble_clone_description(existing_bz) clone_description = " +++ This bug was initially created as a clone of Bug ##{existing_bz[:id]} +++ \n" clone_description << existing_bz[:description.to_s] clone_comment_is_private = false existing_bz[:comments.to_s].each do |comment| clone_description << "\n\n" clone_description << "*" * 70 clone_description << "\nFollowing comment by %s on %s\n\n" % [comment['author'], comment['creation_time'].to_time] clone_description << "\n\n" clone_description << comment['text'] clone_comment_is_private = true if comment['is_private'] end [clone_description, clone_comment_is_private] end
Build a printable representation of the xmlrcp command executed.
# File lib/active_bugzilla/service.rb, line 210 def command_string(cmd, params) clean_params = Hash[params] clean_params[:Bugzilla_password] = "********" "xmlrpc_client.call(#{cmd}, #{clean_params})" end
# File lib/active_bugzilla/service.rb, line 202 def to_xmlrpc_timestamp(ts) return ts if ts.kind_of?(XMLRPC::DateTime) return ts unless ts.respond_to?(:to_time) ts = ts.to_time XMLRPC::DateTime.new(ts.year, ts.month, ts.day, ts.hour, ts.min, ts.sec) end
# File lib/active_bugzilla/service.rb, line 189 def xmlrpc_client @xmlrpc_client ||= ::XMLRPC::Client.new( bugzilla_request_hostname, DEFAULT_CGI_PATH, DEFAULT_PORT, DEFAULT_PROXY_HOST, DEFAULT_PROXY_PORT, username, password, DEFAULT_USE_SSL, timeout || DEFAULT_TIMEOUT) end