/**
  * Notify collaborators of unsuccessful analyses.
  *
  * @param \StyleCI\StyleCI\Models\Analysis $analysis
  * @param \StyleCI\StyleCI\Models\Repo     $repo
  *
  * @return void
  */
 public function notifyNotSuccess(Analysis $analysis, Repo $repo)
 {
     $mail = ['repo' => $repo->name, 'commit' => $analysis->message, 'branch' => $analysis->branch, 'link' => route('analysis', AutoPresenter::decorate($analysis)->id)];
     if (in_array($analysis->status, Analysis::HAS_FAILED, true)) {
         $status = 'failed';
         $mail['subject'] = "[{$repo->name}] Analysis Failed";
     } else {
         switch ($analysis->status) {
             case Analysis::CONFIG_ISSUES:
                 $status = 'misconfigured';
                 $mail['subject'] = "[{$repo->name}] Analysis Misconfigured";
                 break;
             case Analysis::ACCESS_ISSUES:
                 $status = 'access';
                 $mail['subject'] = "[{$repo->name}] Analysis Errored";
                 break;
             case Analysis::TIMEOUT:
                 $status = 'timeout';
                 $mail['subject'] = "[{$repo->name}] Analysis Timed Out";
                 break;
             default:
                 $status = 'errored';
                 $mail['subject'] = "[{$repo->name}] Analysis Errored";
         }
     }
     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']);
         });
     }
 }
 /**
  * Handle the repo event.
  *
  * @param \StyleCI\StyleCI\Events\Repo\RepoEventInterface $event
  *
  * @return void
  */
 public function handle(RepoEventInterface $event)
 {
     $repo = $event->repo;
     $mail = ['repo' => $repo->name];
     if ($event instanceof RepoWasDisabledEvent) {
         $mail['subject'] = "[{$repo->name}] Disabled";
         $view = 'disabled';
     } else {
         $mail['subject'] = "[{$repo->name}] Enabled";
         $mail['link'] = route('repo', $repo->id);
         $view = 'enabled';
     }
     foreach ($this->userRepository->collaborators($repo) as $user) {
         $mail['email'] = $user->email;
         $mail['name'] = AutoPresenter::decorate($user)->first_name;
         $this->mailer->queue("emails.{$view}", $mail, function (Message $message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
     }
 }
 /**
  * Trigger the notification.
  *
  * @param \StyleCI\StyleCI\Models\Repo $repo
  * @param string                       $event
  *
  * @return void
  */
 protected function trigger(Repo $repo, $event)
 {
     $users = $this->userRepository->collaborators($repo);
     $data = AutoPresenter::decorate($repo)->toArray();
     foreach ($users as $user) {
         $this->pusher->trigger("user-{$user->id}", $event, ['event' => $data]);
     }
 }