/** * Handles the request to show a repo. * * @param \StyleCI\StyleCI\Models\Repo $repo * * @return \Illuminate\Http\JsonResponse */ public function handleShow(Repo $repo) { $branch = Request::get('branch', $repo->default_branch); $analyses = $repo->analyses()->visible()->where('branch', $branch)->orderBy('created_at', 'desc')->paginate(50); $pagination = ['total' => $analyses->total(), 'count' => count($analyses->items()), 'per_page' => $analyses->perPage(), 'current_page' => $analyses->currentPage(), 'total_pages' => $analyses->lastPage(), 'links' => ['next_page' => $analyses->nextPageUrl(), 'previous_page' => $analyses->previousPageUrl()]]; return new JsonResponse(['data' => AutoPresenter::decorate($analyses->getCollection())->toArray(), 'pagination' => $pagination]); }
/** * Notify collaborators of successful analyses. * * We only notify them if the previous analysis of this branch failed, or * if this was the first analysis of this branch. * * @param \StyleCI\StyleCI\Models\Analysis $analysis * @param \StyleCI\StyleCI\Models\Repo $repo * * @return void */ public function notifySuccess(Analysis $analysis, Repo $repo) { $previous = $repo->analyses()->where('branch', $analysis->branch)->where('id', '<', $analysis->id)->visible()->latest()->first(); if (!$previous) { $status = 'first'; } elseif ($previous->status > Analysis::PASSED) { $status = 'passed'; } else { return; } $mail = ['repo' => $repo->name, 'commit' => $analysis->message, 'branch' => $analysis->branch, 'link' => route('analysis', AutoPresenter::decorate($analysis)->id), 'subject' => "[{$repo->name}] Analysis Passed"]; foreach ($this->userRepository->collaborators($repo) as $user) { $mail['email'] = $user->email; $mail['name'] = AutoPresenter::decorate($user)->first_name; $this->mailer->queue(["emails.html.{$status}", "emails.text.{$status}"], $mail, function (Message $message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); } }