     |> Enum.into(%{})
   end
 
-  def get_build(project = %Project{}, build_counter) do
+  @doc """
+  Creates or retrieves an `Build` for the given `project` and the given
+  `build_counter`. If there already exists a build entity in the database,
+  it is returned otherwise a new build struct is created.
+  """
+  @spec create_build(Project.t, integer) :: Build.t
+  def create_build(project = %Project{}, build_counter) do
     case Repo.get_by(Build, [project_id: project.id, number: build_counter]) do
       nil -> %Build{project_id: project.id, number: build_counter}
       build -> build

  Broadcast an event. Currently, we use the default topic `build:lobby`.
  """
  def broadcast_event(ev = %BuildEvent{build_counter: counter, coordinate: coord}) do
    changeset = Repo.get_by!(Project, name: coord.project_name)
    |> get_build(counter)
    |> Build.changeset(summerize_build_event(ev))

    case Repo.insert_or_update(changeset) do
      {:ok, _build} ->
        BaumeisterWeb.Endpoint.broadcast("build:lobby", "build_event", event_to_map(ev))
      {:error, changeset} ->
        {:error, changeset}
    end
  end
  def broadcast_event(ev = {_role, _action, _step}) do

  use BaumeisterWeb.Web, :channel

  alias Baumeister.BuildEvent
  alias BaumeisterWeb.Project
  alias BaumeisterWeb.Build

