Esempio n. 1
0
 public function __invoke($badge, $user, $repository)
 {
     try {
         $statistics = $this->statisticsProvider->getStatistics($user, $repository);
         switch ($badge) {
             case self::BADGE_OPEN_ISSUES:
                 $badge = $this->createOpenIssuesBadge($statistics);
                 break;
             case self::BADGE_RESOLUTION:
             default:
                 $badge = $this->createResolutionBadge($statistics);
                 break;
         }
     } catch (RuntimeException $e) {
         if ($e->getMessage() === 'Not Found') {
             $badge = $this->poser->generate('github', 'not-found', self::COLOR_DANGER, 'svg');
         } else {
             $badge = $this->poser->generate('github-api', 'limit', self::COLOR_DANGER, 'svg');
         }
     }
     // Cache the badge for 1 day
     header('Cache-Control: max-age=86400');
     header('Content-type: image/svg+xml');
     echo $badge;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $repository = $input->getArgument('repository');
     list($user, $repository) = explode('/', $repository, 2);
     $statistics = $this->statisticsProvider->getStatistics($user, $repository);
     $output->writeln(sprintf('Median resolution time: <info>%s</info>', $statistics->resolutionTime->formatLong()));
     $output->writeln(sprintf('Open issues: <info>%s%%</info>', intval($statistics->openIssuesRatio * 100)));
 }
 public function getStatistics($user, $repository)
 {
     $key = self::CACHE_NAMESPACE . $user . '/' . $repository;
     $statistics = $this->cache->fetch($key);
     if ($statistics === false) {
         $statistics = $this->wrapped->getStatistics($user, $repository);
         $this->cache->save($key, $statistics);
     }
     return $statistics;
 }
 public function getStatistics($user, $repository)
 {
     $id = $user . '/' . $repository;
     $statistics = $this->cache->get($id);
     if (!$statistics instanceof Statistics) {
         $statistics = $this->wrapped->getStatistics($user, $repository);
         $this->cache->set($id, $statistics);
     }
     return $statistics;
 }
 public function getStatistics($user, $repository)
 {
     // Fetch first, so that if an exception happens, we don't store the repository
     $statistics = $this->wrapped->getStatistics($user, $repository);
     // Store it
     $id = $user . '/' . $repository;
     if (!$this->repositories->get($id)) {
         $this->repositories->set($id, new Repository($id));
     }
     return $statistics;
 }
 public function __invoke($user, $repository)
 {
     try {
         // Fetch statistics eagerly so that results are cached
         // Doing this now avoids that the many badges trigger this several times in parallel
         $this->statisticsProvider->getStatistics($user, $repository);
     } catch (RuntimeException $e) {
         // Silence exception: the error will show on the badges
     }
     echo $this->twig->render('project-check.twig', ['repository' => $user . '/' . $repository]);
 }
Esempio n. 7
0
 public function __invoke($user, $repository)
 {
     try {
         $statistics = $this->statisticsProvider->getStatistics($user, $repository);
     } catch (RuntimeException $e) {
         if ($e->getMessage() === 'Not Found') {
             echo $this->twig->render('not-found.twig');
             return;
         }
         echo $this->twig->render('github-limit.twig');
         return;
     }
     echo $this->twig->render('project.twig', ['repository' => $user . '/' . $repository, 'resolutionTime' => $statistics->resolutionTime, 'openedIssues' => round($statistics->openIssuesRatio * 100)]);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     foreach ($this->repositories as $id => $repository) {
         /** @var Repository $repository */
         $repository = $this->repositories->get($id);
         $slug = $repository->getName();
         $output->writeln(sprintf('Caching statistics for <info>%s</info>', $slug));
         list($user, $repo) = explode('/', $slug, 2);
         try {
             $this->statisticsProvider->getStatistics($user, $repo);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<error>Error while fetching statistics for %s</error>', $slug));
             $output->writeln(sprintf('<error>%s: %s</error>', get_class($e), $e->getMessage()));
         }
     }
 }
 private function update(Repository $repository, OutputInterface $output)
 {
     // Clear the cache
     $this->statisticsCache->set($repository->getName(), null);
     // Warmup the cache
     try {
         list($user, $repositoryName) = explode('/', $repository->getName(), 2);
         $this->statisticsProvider->getStatistics($user, $repositoryName);
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Error while fetching statistics for %s</error>', $repository->getName()));
         $output->writeln(sprintf('<error>%s: %s</error>', get_class($e), $e->getMessage()));
     }
     // Mark the repository updated
     $repository->update();
     $this->repositoryStorage->set($repository->getName(), $repository);
 }