class Bicho::CLI::Commands::Search

Command to search for bugs.

Public Instance Methods

do(global_opts, opts, _args) click to toggle source
# File lib/bicho/cli/commands/search.rb, line 45
def do(global_opts, opts, _args)
  server = ::Bicho::Client.new(global_opts[:bugzilla])
  Bicho.client = server
  # for most parameter we accept arrays, and also multi mode
  # this means parameters come in arrays of arrays
  query = ::Bicho::Query.new
  opts.each do |n, v|
    # skip any option that is not part of SEARCH_FIELDS
    next unless Bicho::SEARCH_FIELDS.map { |x| x[0] }.include?(n)
    next if v.nil? || v.flatten.empty?
    v.flatten.each do |single_val|
      query.send(n.to_sym, single_val)
    end
  end

  case opts[:format]
  when 'prometheus'
    STDOUT.puts Bicho::Export.to_prometheus_push_gateway(query)
  else
    server.search_bugs(query).each do |bug|
      t.say("#{t.color(bug.id.to_s, :headline)} #{bug.summary}")
    end
  end
  0
end