   alias BorsNG.Database.Repo
   alias BorsNG.Database.Status
   alias BorsNG.GitHub
+
+  import Ecto.Query
 
   setup do
     inst = %Installation{installation_xref: 91}

        files: %{"staging.tmp" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
      }}
    # Kick off the new, replacement batch.
    [batch_lo, batch_hi] = Repo.all(Batch.all_for_project(proj.id, :waiting))
    batch_lo
    |> Batch.changeset(%{last_polled: 0})
    |> Repo.update!()

    comments = state[{{:installation, 91}, 14}].comments[1]
    assert comments == ["Has [ci skip], bors build will time out"]
  end

  defp ordered_batches(proj) do
    Batch.all_for_project(proj.id, :waiting)
    |> join(:inner, [b], l in assoc(b, :patches))
    |> join(:inner, [_, l], patch in assoc(l, :patch))
    |> order_by([_, _, p], p.commit)
    |> preload([b, l, p], [patches: {l, patch: p}])
    |> Repo.all()
  end
end
