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


  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
      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 = with %PR{} = pr <- refresh_pr_from_db(pr),
                  %{} = raw_commit <- get_latest_commit(pr),
                  {travis, codeclimate} <- statuses_for_commit(raw_commit, pr),
                  %Commit{} = commit <- find_commit_from_db(travis, raw_commit, pr),
                  %Commit{} = commit <- update_commit(commit, raw_commit, travis, codeclimate, pr), do: commit


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