Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  * @throws \Gitonomy\Git\Exception\RuntimeException
  * @throws \Gitonomy\Git\Exception\InvalidArgumentException
  */
 public function handle()
 {
     $inspector = new Inspector($this->settings);
     $repository = $inspector->getRepositoryByUrl($this->argument('repositoryUrl'));
     $inspectedRepository = $inspector->inspectRepository($repository);
     $header = array_keys((array) $inspectedRepository[key($inspectedRepository)]);
     if (!$this->option('dry-run')) {
         $remote = $inspectedRepository['remote'];
         \Swis\GotLaravel\Models\Results::unguard();
         foreach ($inspectedRepository['results'] as $result) {
             $insert = $result->toArray();
             $insert['remote'] = $remote;
             $insert['author_slug'] = Str::slug($result->getAuthor());
             $insert['created_at'] = Carbon::createFromTimestamp($insert['date']);
             try {
                 \Swis\GotLaravel\Models\Results::updateOrCreate(array_only($insert, ['remote', 'filename', 'line']), $insert);
             } catch (\Exception $e) {
                 $this->error('Couldnt insert: ' . $e->getMessage() . PHP_EOL . print_r($insert, 1));
             }
         }
     }
     reset($inspectedRepository['results']);
     array_walk($inspectedRepository['results'], function (&$row) {
         $row = $row->toArray();
     });
     $this->info($inspectedRepository['remote']);
     $this->table($header, $inspectedRepository['results']);
     Artisan::call('got:normalize-names');
 }
 public function getByUser($slug, $monthsBack = false, $fromMonthsBack = false)
 {
     $query = Results::whereAuthorSlug($slug)->orderBy('created_at', 'DESC');
     if ($monthsBack !== false) {
         if ((int) $monthsBack === 0) {
             $query->whereRaw('YEAR(NOW()) = YEAR(created_at) AND MONTH(NOW()) = MONTH(created_at)');
         } else {
             $query->whereRaw('YEAR(DATE_SUB(NOW(), INTERVAL ' . (int) $monthsBack . ' MONTH)) = YEAR(created_at) 
                 AND MONTH(DATE_SUB(NOW(), INTERVAL ' . (int) $monthsBack . ' MONTH)) = MONTH(created_at)');
         }
     }
     if ($fromMonthsBack !== false) {
         $query->whereRaw('DATE_SUB(NOW(), INTERVAL ' . (int) $fromMonthsBack . ' MONTH) < created_at');
     }
     $this->excludedFiles($query);
     return $query->get();
 }
Ejemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @param Settings $settings
  * @return mixed
  */
 public function handle()
 {
     $client = new \Github\Client();
     if ($this->cache && config('game-of-tests.cache') && class_exists(CacheItemPool::class)) {
         $client->addCache(new CacheItemPool($this->cache));
     }
     $this->info('Getting repository list');
     if ($this->argument('organisation') !== false) {
         $repositories = $client->organization()->repositories($this->argument('organisation'), 'owner');
     }
     $repositoryUrls = array_pluck($repositories, 'clone_url');
     $this->info('Found ' . count($repositoryUrls) . ' repositories on Github');
     $progresbar = $this->output->createProgressBar(count($repositoryUrls));
     $progresbar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message% ');
     $progresbar->setMessage('Searching...');
     \Swis\GotLaravel\Models\Results::unguard();
     $inspector = new Inspector($this->settings);
     foreach ($repositoryUrls as $gitUrl) {
         $repository = $inspector->getRepositoryByUrl($gitUrl);
         // Check modified date
         if (null !== $this->option('modified')) {
             $modifiedTimestamp = strtotime($this->option('modified'));
             /**
              * @var $date \DateTime
              */
             try {
                 $commitDate = $repository->getHeadCommit()->getCommitterDate();
             } catch (\Gitonomy\Git\Exception\ReferenceNotFoundException $e) {
                 $this->error($e->getMessage());
                 $this->error('Error finding reference for ' . $gitUrl);
             }
             if ($modifiedTimestamp === false || $commitDate->getTimestamp() < $modifiedTimestamp) {
                 $progresbar->advance();
                 continue;
             }
         }
         $repository->setLogger(new ConsoleLogger($this->getOutput()));
         $resultSet = $inspector->inspectRepository($repository);
         $remote = $resultSet['remote'];
         if (count($resultSet['results']) > 0) {
             $progresbar->setMessage('Found ' . count($resultSet['results']) . ' tests for ' . $remote);
         }
         if (!$this->option('dry-run')) {
             foreach ($resultSet['results'] as $result) {
                 $insert = $result->toArray();
                 $insert['remote'] = $remote;
                 $insert['author_slug'] = Str::slug($result->getAuthor());
                 $insert['created_at'] = Carbon::createFromTimestamp($insert['date']);
                 try {
                     \Swis\GotLaravel\Models\Results::updateOrCreate(array_only($insert, ['remote', 'filename', 'line']), $insert);
                 } catch (\Exception $e) {
                     $this->error('Couldnt insert: ' . $e->getMessage() . PHP_EOL . print_r($insert, 1));
                 }
             }
         }
         $progresbar->advance();
     }
     Artisan::call('got:normalize-names');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Getting directory list');
     // Bare respoitories
     $directory = rtrim(trim($this->argument('directory')), '/') . '/';
     $scanned_directory = array_diff(scandir($directory), array('..', '.'));
     $this->info('Found ' . count($scanned_directory) . ' directories');
     $progresbar = $this->output->createProgressBar(count($scanned_directory));
     $progresbar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message% ');
     $progresbar->setMessage('Searching...');
     \Swis\GotLaravel\Models\Results::unguard();
     $inspector = new Inspector($this->settings);
     foreach ($scanned_directory as $path) {
         $this->logVerbose('Inpecting: ' . $path);
         if (null !== $this->option('only') && strcmp($path, $this->option('only')) !== 0) {
             $progresbar->advance();
             continue;
         }
         if (null !== $this->option('skippast') && strcmp($path, $this->option('skippast')) <= 0) {
             $progresbar->advance();
             continue;
         }
         $repository = $inspector->getRepositoryByPath($directory . $path);
         // Check modified date
         if (null !== $this->option('modified')) {
             $modifiedTimestamp = strtotime($this->option('modified'));
             /**
              * @var $date \DateTime
              */
             try {
                 $this->logVerbose('Getting commit date');
                 $commitDate = $repository->getHeadCommit()->getCommitterDate();
             } catch (\Gitonomy\Git\Exception\ReferenceNotFoundException $e) {
                 $this->error($e->getMessage());
                 $this->error('Error finding reference for ' . $path);
             }
             if ($modifiedTimestamp === false || $commitDate->getTimestamp() < $modifiedTimestamp) {
                 $progresbar->advance();
                 continue;
             }
             $this->logVerbose('Don\'t skip');
         }
         $repository->setLogger(new ConsoleLogger($this->getOutput()));
         $this->logVerbose('Searching git');
         $resultSet = $inspector->inspectRepository($repository);
         $remote = $resultSet['remote'];
         $this->logVerbose('Found remote ' . $remote);
         if (count($resultSet['results']) > 0) {
             $progresbar->setMessage('Found ' . count($resultSet['results']) . ' tests for ' . $remote);
         }
         if (!$this->option('dry-run')) {
             foreach ($resultSet['results'] as $result) {
                 $insert = $result->toArray();
                 $insert['remote'] = $remote;
                 $insert['author_slug'] = Str::slug($result->getAuthor());
                 $insert['created_at'] = Carbon::createFromTimestamp($result->getDate());
                 try {
                     \Swis\GotLaravel\Models\Results::updateOrCreate(array_only($insert, ['remote', 'filename', 'line']), $insert);
                 } catch (\Exception $e) {
                     $this->error('Couldnt insert: ' . $e->getMessage() . PHP_EOL . print_r($insert, 1));
                 }
             }
         }
         $progresbar->advance();
     }
     Artisan::call('got:normalize-names');
 }