   alias SlackCoder.Repo
   alias SlackCoder.Services.CommitService
   require Logger
-  require Beaker.TimeSeries
   alias Tentacat.Pulls
   alias Tentacat.Commits
   alias Tentacat.Repositories.Statuses

                    |> Stream.filter(&( &1["context"] =~ ~r/codeclimate/ ))
                    |> Enum.take(1) # List is already sorted, first is the latest
                    |> List.first
      commit = 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
      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
    commit || pr.latest_commit
  end

  def conflict_notification(refreshed_pr, pr) do


  defp get_latest_commit(pr) do
    owner = if(pr.fork, do: pr.github_user, else: pr.owner)

    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/ ))
