       count = 1
 
     get "#{app}/#{branch}?limit=#{count}", { }, (err, statusCode, body) ->
-      response = ""
       builds = JSON.parse(body)
-
-      builds.forEach (build) ->
-        response += "Build ##{build.number} (#{build.sha1}) of #{build.repo}/#{build.branch} #{build.status}"
-        response += "(#{build.duration}s) #{build.compare}"
-        response += "\n" if count > 1
+      response = buildsStatus(builds) || "Sorry, no builds found for #{app}/#{branch}"
 
       msg.send response
 

    limit = msg.match[1]
    building = msg.match[2]?
    get "builds?limit=#{limit}&building=#{building}", {}, (err, statusCode, body) ->
      response = ""
      builds = JSON.parse(body)

      if builds.length > 0
        builds.forEach (build) ->
          response += "Build ##{build.number} (#{build.sha1}) of #{build.repo}/#{build.branch} #{build.status}"
          response += "(#{build.duration}s) #{build.compare}"
          response += "\n"

        msg.send response
      else
        msg.send "Builds? Sorry, there's no builds here"

  robot.respond /ci status$/i, (msg) ->
    get "", {}, (err, statusCode, body) ->

    path: url.pathname
    headers:
      "Authorization": "Basic #{auth}"

buildsStatus = (builds) ->
  buildsLength = builds.length
  response = ""

  if buildsLength > 0
    builds.forEach (build) ->
      response += buildStatusMessage(build)
      response += "\n" if buildsLength > 1

  response

buildStatusMessage = (build) ->
  response = ""
  response += "Build ##{build.number} (#{build.sha1}) of #{build.repo}/#{build.branch} #{build.status}"
  response += "(#{build.duration}s) #{build.compare}"
  response += " [Log: #{build.web_url}]"


get = (path, params, cb) ->
  options = defaultOptions()
