class Bugzilla::Bug

rdoc

Bugzilla::Bug

Bugzilla::Bug class is to access the Bugzilla::WebService::Bug API that allows you to file a new bug in Bugzilla or get information about bugs that have already been filed.

Constants

FIELDS_ALL
FIELDS_DETAILS
FIELDS_SUMMARY

Public Instance Methods

get_bugs(bugs, fields = FIELDS_SUMMARY) click to toggle source

rdoc

Bugzilla::Bug#get_bugs(bugs, fields = Bugzilla::Bug::FIELDS_SUMMARY)

Get the bugs information from Bugzilla. either of String or Numeric or Array would be acceptable for bugs. you can specify the fields you want to look up with fields.

FWIW this name conflicts to Bugzilla API but this isn's a primitive method since get_bugs method in WebService API is actually deprecated.

# File lib/bugzilla/bug.rb, line 60
def get_bugs(bugs, fields = FIELDS_SUMMARY)
  params = {}

  params['ids'] = case bugs
  when Array
    bugs
  when Integer || String
    [bugs]
  else
    raise ArgumentError, format('Unknown type of arguments: %s', bugs.class)
  end

  unless fields.nil?
    unless (fields - FIELDS_ALL).empty?
      raise ArgumentError, format('Invalid fields: %s', (FIELDS_ALL - fields).join(' '))
    end
    params['include_fields'] = fields
  end

  result = get(params)

  if fields.nil? || fields == FIELDS_ALL
    get_comments(bugs).each do |id, c|
      result['bugs'].each do |r|
        next unless r['id'].to_s == id.to_s
        r['comments'] = c['comments']
        r['comments'] = [] if r['comments'].nil?
        break
      end
    end
  end

  # 'bugs' is only in interests.
  # XXX: need to deal with 'faults' ?
  result['bugs']
end
get_comments(bugs) click to toggle source

rdoc

Bugzilla::Bug#get_comments(bugs)

# File lib/bugzilla/bug.rb, line 102
def get_comments(bugs)

  params = {}

  # TODO
  # this construction should be refactored to a method
  params['ids'] = case bugs
  when Array
    bugs
  when Integer || String
    [bugs]
  else
    raise ArgumentError, format('Unknown type of arguments: %s', bugs.class)
  end

  result = comments(params)

  # not supporting comment_ids. so drop "comments".
  ret = result['bugs']
  # creation_time was added in Bugzilla 4.4. copy the 'time' value to creation_time if not available for compatibility.
  unless check_version(4.4)[0]
    ret.each do |_id, o|
      o['comments'].each do |c|
        c['creation_time'] = c['time'] unless c.include?('creation_time')
      end
    end
  end

  ret
end

Protected Instance Methods

__add_attachment(cmd, *_args) click to toggle source
# File lib/bugzilla/bug.rb, line 331
def __add_attachment(cmd, *_args)
  requires_version(cmd, 4.0)
  # FIXME
end
__add_comment(cmd, *_args) click to toggle source
# File lib/bugzilla/bug.rb, line 336
def __add_comment(cmd, *_args)
  requires_version(cmd, 3.2)
  # FIXME
end
__update(cmd, *_args) click to toggle source
# File lib/bugzilla/bug.rb, line 341
def __update(cmd, *_args)
  requires_version(cmd, 4.0)
  # FIXME
end
__update_see_also(cmd, *_args) click to toggle source
# File lib/bugzilla/bug.rb, line 346
def __update_see_also(cmd, *_args)
  requires_version(cmd, 3.4)
  # FIXME
end
__update_tags(cmd, *_args) click to toggle source
# File lib/bugzilla/bug.rb, line 351
def __update_tags(cmd, *_args)
  requires_version(cmd, 4.4)
  # FIXME
end
_attachments(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 242
def _attachments(cmd, *args)
  requires_version(cmd, 3.6)

  raise ArgumentError, 'Invalid parameters' unless args[0].is_a?(Hash)

  @iface.call(cmd, args[0])
end
_comments(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 250
def _comments(cmd, *args)
  requires_version(cmd, 3.4)

  raise ArgumentError, 'Invalid parameters' unless args[0].is_a?(Hash)

  @iface.call(cmd, args[0])
end
_create(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 306
def _create(cmd, *args)
  raise ArgumentError, 'Invalid parameters' unless args[0].is_a?(Hash)

  required_fields = %i[product component summary version]
  defaulted_fields = %i[description op_sys platform priority severity]

  res = check_version('3.0.4')
  required_fields.push(*defaulted_fields) unless res[0]
  required_fields.each do |f|
    raise ArgumentError, format("Required fields isn't given: %s", f) unless args[0].include?(f)
  end
  res = check_version(4.0)
  if res[0]
    if args[0].include?('commentprivacy')
      args[0]['comment_is_private'] = args[0]['commentprivacy']
      args[0].delete('commentprivacy')
    end
  else
    raise ArgumentError, "groups field isn't available in this bugzilla" if args[0].include?('groups')
    raise ArgumentError, "comment_is_private field isn't available in this bugzilla" if args[0].include?('comment_is_private')
  end

  @iface.call(cmd, args[0])
end
_fields(cmd, *args) click to toggle source

rdoc

Bugzilla::Bug#create(params)

Raw Bugzilla API to create a new bug in Bugzilla.

See www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html

# File lib/bugzilla/bug.rb, line 214
def _fields(cmd, *args)
  requires_version(cmd, 3.6)
  params = {}
  a = args[0]
  case a
  when Array
    is = a.map { |x| x.is_a?(Integer) }.uniq
    params['ids'] = a if is.size == 1 && is[0]
    ss = a.map { |x| x.is_a?(String) }.uniq
    params['names'] = a if ss.size == 1 && ss[0]
  when Hash
    params = a
  when Integer
    params['ids'] = [a]
  when String
    params['names'] = [a]
  else
    raise ArgumentError, 'Invalid parameters'
  end
  @iface.call(cmd, params)
end
_get(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 258
def _get(cmd, *args)
  params = {}

  a = args[0]

  case a
  when Hash
    params = a
  when Array
    params['ids'] = a
  when Integer || String
    params['ids'] = [a]
  else
    raise ArgumentError, 'Invalid parameters'
  end

  params['permissive'] = true if check_version(3.4)[0]

  @iface.call(cmd, params)
end
_history(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 279
def _history(cmd, *args)
  requires_version(cmd, 3.4)

  params = {}
  a = args[0]
  case a
  when Hash
    params = a
  when Array
    params['ids'] = a
  when Integer || String
    params['ids'] = [a]
  else
    raise ArgumentError, 'Invalid parameters'
  end

  @iface.call(cmd, params)
end