class ActiveBugzilla::Service

Constants

CLONE_FIELDS
DEFAULT_CGI_PATH
DEFAULT_PORT
DEFAULT_PROXY_HOST
DEFAULT_PROXY_PORT
DEFAULT_TIMEOUT
DEFAULT_USE_SSL

Attributes

bugzilla_request_hostname[R]
bugzilla_request_uri[R]
bugzilla_uri[RW]
last_command[RW]
password[RW]
username[RW]

Public Class Methods

new(bugzilla_uri, username, password) click to toggle source
# 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
product() click to toggle source
# File lib/active_bugzilla/service.rb, line 47
def self.product
  defined?(@@product) && @@product
end
product=(value) click to toggle source
# File lib/active_bugzilla/service.rb, line 43
def self.product=(value)
  @@product = value
end
timeout() click to toggle source
# File lib/active_bugzilla/service.rb, line 35
def self.timeout
  defined?(@@timeout) && @@timeout
end
timeout=(value) click to toggle source
# File lib/active_bugzilla/service.rb, line 31
def self.timeout=(value)
  @@timeout = value
end

Public Instance Methods

add_comment(bug_id, comment, params = {}) click to toggle source

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
bugzilla_uri=(value) click to toggle source
# 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(bug_id, overrides = {}) click to toggle source

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
comments(params = {}) click to toggle source

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
create(params) click to toggle source

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
execute(action, params) click to toggle source

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
fields(params = {}) click to toggle source

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
get(bug_ids, params = {}) click to toggle source

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
inspect() click to toggle source
Calls superclass method
# File lib/active_bugzilla/service.rb, line 69
def inspect
  super.gsub(/@password=\".+?\", /, "")
end
product() click to toggle source
# File lib/active_bugzilla/service.rb, line 51
def product
  self.class.product
end
timeout() click to toggle source
# File lib/active_bugzilla/service.rb, line 39
def timeout
  self.class.timeout
end
update(ids, params = {}) click to toggle source

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

assemble_clone_description(existing_bz) click to toggle source
# 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
command_string(cmd, params) click to toggle source

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
to_xmlrpc_timestamp(ts) click to toggle source
# 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
xmlrpc_client() click to toggle source
# 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