 # Hubot has to be running as a user who has registered a SSH key with Gerrit.
 #
 # hubot gerrit search <query> - Search Gerrit for changes - the query should follow the normal Gerrit query rules.
-# hubot gerrit ignore events for <project> - Don't spam about events happening for the specified project.
-# hubot gerrit report events for <project> - Reset Hubot to spam about events happening for the specified project.
+# hubot gerrit (ignore|report) events for (project|user|event) <thing> - Tell Hubot how to report Gerrit events.
 #
 
 # Required - The SSH URL for your Gerrit server.

  else
    eventStreamMe robot, gerrit unless eventStreamRooms == "disabled"
    robot.respond /gerrit (?:search|query)(?: me)? (.+)/i, searchMe robot, gerrit
    robot.respond /gerrit (ignore|report)(?: me)? events for (.+)/i, ignoreOrReportEventsMe robot, gerrit

searchMe = (robot, gerrit) -> (msg) ->
  cp.exec "ssh #{gerrit.hostname} -p #{gerrit.port} gerrit query --format=JSON #{msg.match[1]}", (err, stdout, stderr) ->

    robot.logger.info "Gerrit stream-events: Connection lost (rc=#{code})"
    reconnect = setTimeout (-> eventStreamMe robot, gerrit), 10 * 1000 unless done

  isIgnored = (type, thing) -> (t for t in ignoresOfType robot, type when t is thing).length != 0
  isWanted = (event) -> !(
    isIgnored("project", extractProject event) ||
    isIgnored("user", extractName event) ||
    isIgnored("event", event.type))

  streamEvents.stderr.on "data", (data) ->
    robot.logger.info "Gerrit stream-events: #{data}"
