   end
 
   def get_new_batch(project_id) do
-    case Repo.get_by(Batch, project_id: project_id, state: 0) do
+    case Repo.get_by(Batch, project_id: project_id, state: Batch.numberize_state(:waiting)) do
       nil -> Repo.insert!(Batch.new(project_id))
       batch -> batch
     end

    token = GitHub.get_installation_token!(project.installation.installation_xref)
    stmp = "#{project.staging_branch}.tmp"
    patches = Repo.all(Patch.all_for_batch(batch.id))
    base = GitHub.copy_branch!(token, project.repo_xref, project.master_branch, stmp)
    do_merge_patch = fn patch, _branch ->
      GitHub.merge_branch!(token, project.repo_xref, patch.commit, stmp, "tmp")

    project = batch.project
    token = GitHub.get_installation_token!(project.installation.installation_xref)
    GitHub.copy_branch!(token, project.repo_xref, project.staging_branch, project.master_branch)
    patches = Repo.all(Patch.all_for_batch(batch.id))
    |> Enum.sort_by(&(&1.pr_xref))
    |> Enum.dedup_by(&(&1.pr_xref))
    body = Enum.reduce(succeeded, "# Build succeeded", &gen_status_link/2)
    Enum.each(patches, &GitHub.post_comment!(token, project.repo_xref, &1.pr_xref, body))
  end
