   defp create_build(project = %WP{}, build_counter) do
     case Repo.get_by(WB, [project_id: project.id, number: build_counter]) do
       nil -> %WB{project_id: project.id, number: build_counter, id: nil}
+            |> convert_up_build()
       build -> build
     end
   end

  @spec get_project(integer) :: Project
  def get_project(id) when is_integer(id) do
    Repo.get!(WP, id)
    |> convert_up()
  end

  @doc """

      new_p
    else
      # Logger.debug "convert_up: load last_build #{p.last_build_id}"
      last_build = Repo.get_by(WB, [number: p.last_build_id, project_id: p.id]) |> convert_up_build
      # Logger.debug "last_build is #{inspect last_build}"
      %Project{new_p | last_build: last_build}
    end
  end

  @spec convert_up_project(WB.t) :: Build.t
  defp convert_up_build(b = %WB{}) do
    fields = [:number, :log, :coordinate, :config, :status, :id,
      :updated_at, :inserted_at, :project_id]
    |> Enum.map(fn f -> {f, Map.get(b, f)} end)
    struct!(%Build{}, fields)
  end


  @doc """
  Returns all projects.
  """
  @spec list_projects() :: [Project.t]
  def list_projects() do
    Repo.all(WP) |> Enum.map(&convert_up_project/1)
  end

  @doc """
