Esempio n. 1
0
 /**
  * View detail of video
  * 
  * @param type $slug
  * @param \App\Repositories\PostInterface $videoRepository
  * @return \Illuminate\View\View
  */
 public function viewDetail($slug, VideoInterface $videoRepository)
 {
     $video = $videoRepository->findBy('slug', $slug)->first();
     $relatedVideos = $videoRepository->getRelatedVideo($video->category_id);
     $data = ['video' => AutoPresenter::decorate($video), 'relatedVideos' => AutoPresenter::decorate($relatedVideos)];
     return view('video.detail', $data);
 }
Esempio n. 2
0
 /**
  * View detail of post
  * 
  * @param type $slug
  * @param \App\Repositories\PostInterface $postRepository
  * @return \Illuminate\View\View
  */
 public function viewDetail($slug, PostInterface $postRepository)
 {
     $post = $postRepository->findBy('slug', $slug)->first();
     $relatedPosts = $postRepository->getRelatedPost($post->category_id);
     $data = ['post' => AutoPresenter::decorate($post), 'relatedPosts' => AutoPresenter::decorate($relatedPosts)];
     return view('post.detail', $data);
 }
Esempio n. 3
0
 /**
  * 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]);
 }
Esempio n. 4
0
 public function testPresentation()
 {
     $repo = Repo::create(['id' => '12345', 'user_id' => '4242', 'name' => 'Foo/Baz', 'default_branch' => 'lol', 'token' => str_repeat('a', 20)]);
     $presented = AutoPresenter::decorate($repo);
     $this->assertInstanceOf(RepoPresenter::class, $presented);
     $this->assertSame(12345, $presented->id);
     $this->assertSame(['id' => 12345, 'last_analysis' => null, 'name' => 'Foo/Baz', 'default_branch' => 'lol', 'link' => url('/repos/12345')], $presented->toArray());
 }
 /**
  * Handle the user has signed up event.
  *
  * @param \StyleCI\StyleCI\Events\User\UserHasSignedUpEvent $event
  *
  * @return void
  */
 public function handle(UserHasSignedUpEvent $event)
 {
     $user = $event->user;
     $mail = ['email' => $user->email, 'name' => AutoPresenter::decorate($user)->first_name, 'subject' => 'Welcome'];
     $this->mailer->queue('emails.welcome', $mail, function (Message $message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
 }
 /**
  * Handle the user has rage quit event.
  *
  * @param \StyleCI\StyleCI\Events\User\UserHasRageQuitEvent $event
  *
  * @return void
  */
 public function handle(UserHasRageQuitEvent $event)
 {
     $user = $event->user;
     $mail = ['email' => $user->email, 'name' => AutoPresenter::decorate($user)->first_name, 'subject' => 'Account Deleted'];
     $this->mailer->queue(['html' => 'emails.html.goodbye', 'text' => 'emails.text.goodbye'], $mail, function (Message $message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
 }
 public function testHandle()
 {
     $data = json_decode(file_get_contents(__DIR__ . '/stubs/ping.json'), true);
     $handler = new GitHubPingHandler($log = Mockery::mock(LoggerInterface::class));
     AutoPresenter::shouldReceive('decorate')->once()->with($repo = new Repo())->andReturn($presenter = Mockery::mock(RepoPresenter::class));
     $presenter->shouldReceive('toArray')->once()->andReturn($presented = ['id' => 26929642, 'name' => 'StyleCI/StyleCI']);
     $log->shouldReceive('info')->once()->with('Received ping from GitHub.', ['data' => $data, 'repo' => $presented]);
     $this->assertNull($handler->handle(new GitHubPingEvent($repo, $data)));
 }
Esempio n. 8
0
 /**
  * Push the status on the github analysis.
  *
  * @param \StyleCI\StyleCI\Models\Analysis $analysis
  *
  * @return void
  */
 public function push(Analysis $analysis)
 {
     $repo = $analysis->repo;
     $args = explode('/', $repo->name);
     $decorated = AutoPresenter::decorate($analysis);
     $data = ['state' => $this->getState($decorated->status), 'description' => $this->getDescription($decorated), 'target_url' => route('analysis', $decorated->id), 'context' => 'StyleCI'];
     $client = $this->factory->make($repo);
     $client->repos()->statuses()->create($args[0], $args[1], $analysis->commit, $data);
 }
Esempio n. 9
0
 public function testPresentation()
 {
     $user = User::create(['id' => '12345', 'name' => 'Foo Baz', 'username' => 'baz', 'email' => '*****@*****.**', 'token' => str_repeat('a', 40)]);
     $presented = AutoPresenter::decorate($user);
     $this->assertInstanceOf(UserPresenter::class, $presented);
     $this->assertSame(12345, $presented->id);
     $this->assertSame('Foo', $presented->first_name);
     $this->assertSame('https://www.gravatar.com/avatar/1f58cc55c53a9a863f6f2c1fb73d1334?size=200', $presented->gravatar);
 }
Esempio n. 10
0
 /**
  * Show the application dashboard to the user.
  *
  * @param VideoInterface $video
  * @return Response
  */
 public function index(VideoInterface $videoRepository, PostInterface $postRepository)
 {
     // Get posts
     $posts = $postRepository->all()->take(6);
     // Get videos
     $videos = $videoRepository->all()->take(6);
     // Bind data to view
     $data = ['posts' => AutoPresenter::decorate($posts), 'videos' => AutoPresenter::decorate($videos)];
     return view('home.home', $data);
 }
 /**
  * Send notification to subscriber.
  *
  * @param \CachetHQ\Cachet\Models\Component  $component
  * @param \CachetHQ\Cachet\Models\Subscriber $subscriber
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function notify(Component $component, Subscriber $subscriber)
 {
     $component = AutoPresenter::decorate($component);
     $mail = ['subject' => trans('cachet.subscriber.email.component.subject'), 'component_name' => $component->name, 'component_human_status' => $component->human_status];
     $mail['email'] = $subscriber->email;
     $mail['manage_link'] = route('subscribe.manage', ['code' => $subscriber->verify_code]);
     $this->mailer->queue(['html' => 'emails.components.update-html', 'text' => 'emails.components.update-text'], $mail, function (Message $message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
 }
 /**
  * Handle the event.
  *
  * @param \CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent $event
  *
  * @return void
  */
 public function handle(MaintenanceWasScheduledEvent $event)
 {
     $data = AutoPresenter::decorate($event->incident);
     foreach ($this->subscriber->all() as $subscriber) {
         $mail = ['email' => $subscriber->email, 'subject' => 'Scheduled maintenance.', 'status' => $data->humanStatus, 'html_content' => $data->formattedMessage, 'text_content' => $data->message, 'scheduled_at' => $data->scheduled_at_formatted, 'token' => $subscriber->token, 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]), 'app_url' => env('APP_URL')];
         $this->mailer->queue(['html' => 'emails.incidents.maintenance-html', 'text' => 'emails.incidents.maintenance-text'], $mail, function (Message $message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
     }
 }
 /**
  * Handle the event.
  *
  * @param \CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent $event
  *
  * @return void
  */
 public function handle(ComponentWasUpdatedEvent $event)
 {
     $component = AutoPresenter::decorate($event->component);
     $mail = ['subject' => trans('cachet.subscriber.email.component.subject'), 'component_name' => $component->name, 'component_human_status' => $component->human_status];
     foreach (Subscription::isVerifiedForComponent($component->id)->with('subscriber')->get() as $subscription) {
         $subscriber = $subscription->subscriber;
         $mail['email'] = $subscriber->email;
         $mail['unsubscribe_link'] = route('subscribe.unsubscribe', ['code' => $subscriber->verify_code, 'subscription' => $subscription->id]);
         $this->mailer->queue(['html' => 'emails.components.update-html', 'text' => 'emails.components.update-text'], $mail, function (Message $message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
     }
 }
 /**
  * Handle the event.
  *
  * @param \CachetHQ\Cachet\Events\Incident\IncidentHasReportedEvent $event
  *
  * @return void
  */
 public function handle(IncidentWasReportedEvent $event)
 {
     $incident = AutoPresenter::decorate($event->incident);
     $component = AutoPresenter::decorate($event->incident->component);
     // Only send emails for public incidents.
     if ($event->incident->visible === 1) {
         foreach ($this->subscriber->all() as $subscriber) {
             $mail = ['email' => $subscriber->email, 'subject' => 'New incident reported.', 'has_component' => $event->incident->component ? true : false, 'component_name' => $component ? $component->name : null, 'status' => $incident->humanStatus, 'html_content' => $incident->formattedMessage, 'text_content' => $incident->message, 'token' => $subscriber->token, 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]), 'app_url' => env('APP_URL')];
             $this->mailer->queue(['html' => 'emails.incidents.new-html', 'text' => 'emails.incidents.new-text'], $mail, function (Message $message) use($mail) {
                 $message->to($mail['email'])->subject($mail['subject']);
             });
         }
     }
 }
 /**
  * Handle the event.
  *
  * @param \Gitamin\Events\Issue\IssueHasAddedEvent $event
  *
  * @return void
  */
 public function handle(IssueWasAddedEvent $event)
 {
     if (!$event->issue->notify) {
         return false;
     }
     $issue = AutoPresenter::decorate($event->issue);
     $project = AutoPresenter::decorate($event->issue->project);
     // Only send emails for public issues.
     if ($event->issue->visible === 1) {
         foreach ($this->subscriber->all() as $subscriber) {
             $mail = ['email' => $subscriber->email, 'subject' => 'New issue reported.', 'has_project' => $event->issue->project ? true : false, 'project_name' => $project ? $project->name : null, 'status' => $issue->humanStatus, 'html_content' => $issue->formattedMessage, 'text_content' => $issue->message, 'token' => $subscriber->token, 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code])];
             $this->mailer->queue(['html' => 'emails.issues.new-html', 'text' => 'emails.issues.new-text'], $mail, function (Message $message) use($mail) {
                 $message->to($mail['email'])->subject($mail['subject']);
             });
         }
     }
 }
Esempio n. 16
0
 /**
  * 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']);
         });
     }
 }
Esempio n. 17
0
 public function author_url()
 {
     return AutoPresenter::decorate($this->wrappedObject->author)->url;
 }
 /**
  * Respond with a pagination response.
  *
  * @param \Illuminate\Pagination\Paginator $paginator
  * @param \Illuminate\Http\Request         $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 protected function paginator(Paginator $paginator, Request $request)
 {
     foreach ($request->query as $key => $value) {
         if ($key != 'page') {
             $paginator->addQuery($key, $value);
         }
     }
     $pagination = ['pagination' => ['total' => (int) $paginator->total(), 'count' => count($paginator->items()), 'per_page' => (int) $paginator->perPage(), 'current_page' => (int) $paginator->currentPage(), 'total_pages' => (int) $paginator->lastPage(), 'links' => ['next_page' => $paginator->nextPageUrl(), 'previous_page' => $paginator->previousPageUrl()]]];
     $items = $paginator->getCollection();
     if ($sortBy = $request->get('sort')) {
         $direction = $request->has('order') && $request->get('order') == 'desc';
         $items = $items->sortBy($sortBy, SORT_REGULAR, $direction);
     }
     return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($items->values()))->respond();
 }
Esempio n. 19
0
 /**
  * Get the last analysis that's actually been completed.
  *
  * @return \StyleCI\StyleCI\Presenters\AnalysisPresenter|null
  */
 protected function last_completed()
 {
     if ($analysis = $this->wrappedObject->last_completed) {
         return AutoPresenter::decorate($analysis);
     }
 }
 /**
  * Get the context.
  *
  * @param \StyleCI\StyleCI\Models\Analysis $analysis
  *
  * @return array
  */
 protected function getContext(Analysis $analysis)
 {
     return ['analysis' => AutoPresenter::decorate($analysis)->toArray()];
 }
Esempio n. 21
0
 /**
  * Respond with a pagination response.
  *
  * @param \Illuminate\Pagination\Paginator $paginator
  * @param \Illuminate\Http\Request         $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 protected function paginator(Paginator $paginator, Request $request)
 {
     foreach ($request->query as $key => $value) {
         if ($key != 'page') {
             $paginator->addQuery($key, $value);
         }
     }
     $pagination = ['pagination' => ['total' => $paginator->total(), 'count' => count($paginator->items()), 'per_page' => $paginator->perPage(), 'current_page' => $paginator->currentPage(), 'total_pages' => $paginator->lastPage(), 'links' => ['next_page' => $paginator->nextPageUrl(), 'previous_page' => $paginator->previousPageUrl()]]];
     return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($paginator->getCollection()))->respond();
 }
Esempio n. 22
0
 /**
  * Get the context.
  *
  * @param \StyleCI\StyleCI\Models\Repo $repo
  *
  * @return array
  */
 protected function getContext(Repo $repo)
 {
     return ['repo' => AutoPresenter::decorate($repo)->toArray()];
 }
 /**
  * Returns the lowest component status color.
  *
  * @return string|null
  */
 public function lowest_status_color()
 {
     if ($component = $this->wrappedObject->enabled_components_lowest()->first()) {
         return AutoPresenter::decorate($component)->status_color;
     }
 }
 /**
  * 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']);
         });
     }
 }
 /**
  * Generates a Shield (badge) for the component.
  *
  * @param \CachetHQ\Cachet\Models\Component $component
  *
  * @return \Illuminate\Http\Response
  */
 public function showComponentBadge(Component $component)
 {
     $component = AutoPresenter::decorate($component);
     $color = null;
     switch ($component->status_color) {
         case 'reds':
             $color = Config::get('setting.style_reds', '#ff6f6f');
             break;
         case 'blues':
             $color = Config::get('setting.style_blues', '#3498db');
             break;
         case 'greens':
             $color = Config::get('setting.style_greens', '#7ED321');
             break;
         case 'yellows':
             $color = Config::get('setting.style_yellows', '#F7CA18');
             break;
     }
     $badge = Badger::generate($component->name, $component->human_status, substr($color, 1), Binput::get('style', 'flat-square'));
     return Response::make($badge, 200, ['Content-Type' => 'image/svg+xml']);
 }
Esempio n. 26
0
 /**
  * Bind data to the view.
  *
  * @param \Illuminate\Contracts\View\View $view
  *
  * @return void
  */
 public function compose(View $view)
 {
     $view->withCurrentUser(AutoPresenter::decorate(Auth::user()));
 }
Esempio n. 27
0
 public function testPresentation()
 {
     $analysis = Analysis::create(['repo_id' => 12345, 'branch' => 'test', 'commit' => str_repeat('a', 40), 'message' => 'Test 123!', 'status' => 2, 'hidden' => 1]);
     $presented = AutoPresenter::decorate($analysis);
     $this->assertInstanceOf(AnalysisPresenter::class, $presented);
     $this->assertSame('xkXG8Z', $presented->id);
     $this->assertSame('PASSED', $presented->summary);
     $this->assertSame('The StyleCI analysis has passed', $presented->description);
     $this->assertSame('fa fa-check-circle', $presented->icon);
     $this->assertSame('green', $presented->color);
     $this->assertFalse($presented->has_diff);
 }
Esempio n. 28
0
 /**
  * Handles the request to download a diff.
  *
  * @param \StyleCI\StyleCI\Models\Analysis $analysis
  *
  * @return \Illuminate\Http\Response
  */
 public function handleDiffDownload(Analysis $analysis)
 {
     return Response::make(AutoPresenter::decorate($analysis)->raw_diff)->header('Content-Type', 'text/plain; charset=UTF-8')->header('Content-Disposition', 'attachment; filename=patch.txt');
 }
 /**
  * Send notification to subscriber.
  *
  * @param \CachetHQ\Cachet\Bus\Events\IncidentWasReportedEvent $event
  * @param \CachetHQ\Cachet\Models\Subscriber                   $subscriber
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function notify(IncidentWasReportedEvent $event, $subscriber)
 {
     $incident = AutoPresenter::decorate($event->incident);
     $component = AutoPresenter::decorate($event->incident->component);
     $mail = ['email' => $subscriber->email, 'subject' => trans('cachet.subscriber.email.incident.subject', ['status' => $incident->human_status, 'name' => $incident->name]), 'has_component' => $event->incident->component ? true : false, 'component_name' => $component ? $component->name : null, 'name' => $incident->name, 'timestamp' => $incident->created_at_formatted, 'status' => $incident->human_status, 'html_content' => $incident->formattedMessage, 'text_content' => $incident->message, 'token' => $subscriber->token, 'manage_link' => route('subscribe.manage', ['code' => $subscriber->verify_code]), 'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code])];
     $this->mailer->queue(['html' => 'emails.incidents.new-html', 'text' => 'emails.incidents.new-text'], $mail, function (Message $message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
 }
Esempio n. 30
-5
 /**
  * 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]);
     }
 }