class Bugzilla::Bug

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 = ::Bugzilla::Bug::FIELDS_SUMMARY) click to toggle source

#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 64
def get_bugs(bugs, fields = ::Bugzilla::Bug::FIELDS_SUMMARY)
  params = {}

  if bugs.kind_of?(Array) then
    params['ids'] = bugs
  elsif bugs.kind_of?(Integer) ||
      bugs.kind_of?(String) then
    params['ids'] = [bugs]
  else
    raise ArgumentError, sprintf("Unknown type of arguments: %s", bugs.class)
  end
  unless fields.nil? then
    unless (fields - ::Bugzilla::Bug::FIELDS_ALL).empty? then
      raise ArgumentError, sprintf("Invalid fields: %s", (::Bugzilla::Bug::FIELDS_ALL - fields).join(' '))
    end
    params['include_fields'] = fields
  end

  result = get(params)

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

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

#get_comments

# File lib/bugzilla/bug.rb, line 107
def get_comments(bugs)
  params = {}

  if bugs.kind_of?(Array) then
    params['ids'] = bugs
  elsif bugs.kind_of?(Integer) ||
      bugs.kind_of?(String) then
    params['ids'] = [bugs]
  else
    raise ArgumentError, sprintf("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] then
    ret.each do |id, o|
      o['comments'].each do |c|
        unless c.include?('creation_time') then
          c['creation_time'] = c['time']
        end
      end
    end
  end

  ret
end

Protected Instance Methods

__add_attachment(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 350
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 355
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 360
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 365
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 370
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 260
def _attachments(cmd, *args)
  requires_version(cmd, 3.6)

  raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)

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

  raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)

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

  required_fields = [:product, :component, :summary, :version]
  defaulted_fields = [:description, :op_sys, :platform, :priority, :severity]

  res = check_version("3.0.4")
  unless res[0] then
        required_fields.push(*defaulted_fields)
  end
  required_fields.each do |f|
    raise ArgumentError, sprintf("Required fields isn't given: %s", f) unless args[0].include?(f)
  end
  res = check_version(4.0)
  unless res[0] then
    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")
  else
    if args[0].include?("commentprivacy") then
      args[0]["comment_is_private"] = args[0]["commentprivacy"]
      args[0].delete("commentprivacy")
    end
  end

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

Bugzilla::Bug#fields(params)

Raw Bugzilla API to obtain the information about valid bug fields, including the lists of legal values for each field.

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

Bugzilla::Bug#legal_values(params)

Raw Bugzilla API to obtain the information what values are allowed for a particular field.

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

Bugzilla::Bug#attachments(params)

Raw Bugzilla API to obtain the information about attachments, given a list of bugs and/or attachment ids.

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

Bugzilla::Bug#comments(params)

Raw Bugzilla API to obtain the information about comments, given a list of bugs and/or comment ids.

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

Bugzilla::Bug#get(params)

Raw Bugzilla API to obtain the information about particular bugs in the database.

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

Bugzilla::Bug#history(params)

Raw Bugzilla API to obtain the history of changes for particular bugs in the database.

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

Bugzilla::Bug#search(params)

Raw Bugzilla API to search for bugs based on particular criteria.

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

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 226
def _fields(cmd, *args)
  requires_version(cmd, 3.6)
  params = {}

  if args[0].kind_of?(Array) then
    x = args[0].map {|x| x.kind_of?(Integer)}.uniq
    if x.length == 1 && x[0] then
      params['ids'] = args[0]
    else
      x = args[0].map {|x| x.kind_of?(String)}.uniq
      if x.length == 1 && x[0] then
        params['names'] = args[0]
      end
    end
  elsif args[0].kind_of?(Hash) then
    params = args[0]
  elsif args[0].kind_of?(Integer) then
    params['ids'] = [args[0]]
  elsif args[0].kind_of?(String) then
    params['names'] = [args[0]]
  elsif args[0].nil? then
  else
    raise ArgumentError, "Invalid parameters"
  end

  @iface.call(cmd, params)
end
_get(cmd, *args) click to toggle source
# File lib/bugzilla/bug.rb, line 276
def _get(cmd, *args)
  params = {}

  if args[0].kind_of?(Hash) then
    params = args[0]
  elsif args[0].kind_of?(Array) then
    params['ids'] = args[0]
  elsif args[0].kind_of?(Integer) ||
      args[0].kind_of?(String) then
    params['ids'] = [args[0]]
  else
    raise ArgumentError, "Invalid parameters"
  end
  if check_version(3.4)[0] then
    params['permissive'] = true
  end

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

  params = {}

  if args[0].kind_of?(Hash) then
    params = args[0]
  elsif args[0].kind_of?(Array) then
        params['ids'] = args[0]
  elsif args[0].kind_of?(Integer) ||
    args[0].kind_of?(String) then
        params['ids'] = [args[0]]
  else
    raise ArgumentError, "Invalid parameters"
  end

  @iface.call(cmd, params)
end