 
   defp get_latest_commit(pr) do
     owner = if(pr.fork, do: pr.github_user, else: pr.owner)
-    last_commit = Commits.filter(owner, pr.repo, %{sha: pr.branch}, Github.client)
-                  |> List.first
-
-    commit = if last_commit["sha"] do # 404 returned when user deletes branch
+
+    Commits.filter(owner, pr.repo, %{sha: pr.branch}, Github.client)
+    |> List.first
+  end
+
+  defp statuses_for_commit(last_commit, pr) do
+    if last_commit["sha"] do # 404 returned when user deletes branch
       statuses = Statuses.find(pr.owner, pr.repo, last_commit["sha"])
       last_status = statuses
                     |> Stream.filter(&( &1["context"] =~ ~r/travis/ ))

  end

  defp _status(pr) do
    commit = pr
             |> refresh_pr_from_db
             |> get_latest_commit

    refreshed_pr = Pulls.find(pr.owner, pr.repo, pr.number, Github.client)
                  |> build_pr(pr)

                    |> Stream.filter(&( &1["context"] =~ ~r/codeclimate/ ))
                    |> Enum.take(1) # List is already sorted, first is the latest
                    |> List.first

      {last_status, code_climate}
    end
  end

  defp find_commit_from_db(last_status, last_commit, pr) do
    if pr.latest_commit && pr.latest_commit.latest_status_id == last_status["id"] do
      pr.latest_commit
    else
      Repo.get_by(Commit, sha: last_commit["sha"]) || %Commit{}
    end
  end

  defp update_commit(commit, last_commit, last_status, code_climate, pr) do
    cs = Commit.changeset(commit, %{
          status: if(pr.mergeable, do: last_status["state"] || "pending", else: "conflict"),
          code_climate_status: code_climate["state"] || "pending",
          travis_url: last_status["target_url"],
          code_climate_url: code_climate["target_url"],
          sha: last_commit["sha"],
          github_user: last_commit["author"]["login"],
          github_user_avatar: last_commit["author"]["avatar_url"],
          latest_status_id: last_status["id"],
          pr_id: pr.id
         })
    {:ok, commit} = CommitService.save(cs)
    commit
  end

  def conflict_notification(refreshed_pr, pr) do
