コード例 #1
0
ファイル: AddCommit.php プロジェクト: funivan/ci
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $commit = new Commit();
     $commit->status = Commit::STATUS_PENDING;
     $commit->branch = $this->argument('branch');
     $commit->hash = $this->argument('hash');
     $commit->start_time = time();
     $commit->end_time = 0;
     $commit->save();
     $this->getOutput()->writeln('Added. Id: ' . $commit->id);
 }
コード例 #2
0
ファイル: LoggerFactory.php プロジェクト: funivan/ci
 /**
  * @param Commit $commit
  * @return Logger
  */
 public static function createLogger(\App\Models\Commit $commit)
 {
     $file = $commit->getLogFilePath();
     if (is_file($file)) {
         unlink($file);
     }
     # create a log channel
     $logger = new Logger('commit.check');
     $defaultLoggerStream = new StreamHandler($file, \Monolog\Logger::DEBUG);
     $defaultLoggerStream->setFormatter(new JsonFormatter());
     $logger->pushHandler($defaultLoggerStream);
     return $logger;
 }
コード例 #3
0
ファイル: Commits.php プロジェクト: funivan/ci
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     for ($i = 0; $i < 10; $i++) {
         $faker = Factory::create();
         $commit = new Commit();
         $commit->status = $faker->randomElement([Commit::STATUS_PENDING, Commit::STATUS_OK, Commit::STATUS_IN_PROGRESS, Commit::STATUS_FAILURE]);
         $commit->hash = $faker->hexColor;
         $commit->branch = $faker->randomElement(['master', 'u-text']);
         $commit->profile = $faker->randomElement(['test', 'consistency', '']);
         $commit->author_email = $faker->email;
         $commit->start_time = $faker->unixTime;
         $commit->message = $faker->realText(random_int(10, 60));
         $commit->end_time = $faker->unixTime;
         $commit->save();
     }
 }
コード例 #4
0
ファイル: CommitController.php プロジェクト: funivan/ci
 /**
  * @param $commit
  * @return array
  */
 private function getLogLines(Commit $commit)
 {
     $lines = [];
     $filePath = $commit->getLogFilePath();
     if (!is_file($filePath)) {
         return $lines;
     }
     $resource = fopen($filePath, 'r');
     while (!feof($resource)) {
         $line = fgets($resource);
         $data = json_decode($line);
         if (empty($data)) {
             continue;
         }
         $lines[] = $data;
     }
     fclose($resource);
     return $lines;
 }
コード例 #5
0
ファイル: DeleteCommit.php プロジェクト: funivan/ci
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $id = $this->argument('id');
     /** @var Commit $commit */
     $commit = Commit::query()->where('id', '=', $id)->get()->first();
     if (empty($commit)) {
         $this->getOutput()->writeln('<error>Cant find commit with id:' . $id . '</error>');
         return;
     }
     $commit->delete();
 }
コード例 #6
0
ファイル: Check.php プロジェクト: funivan/ci
 /**
  * Execute the console command.
  * @throws \Exception
  */
 public function handle()
 {
     $id = $this->option('id');
     /** @var Commit $commit */
     $query = Commit::query();
     $query = $query->where('id', '=', $id);
     $commit = $query->get()->first();
     if (empty($commit)) {
         $this->getOutput()->writeln('<error>Cant find commit:' . $id . '</error>');
         return;
     }
     $checker = new \App\Ci\Checker\ScheduledChecker();
     /** @var OutputStyle $output */
     $output = $this->getOutput();
     $checker->check($commit, new PsrHandler(new ConsoleLogger($output)));
 }
コード例 #7
0
ファイル: CleanCommits.php プロジェクト: funivan/ci
 /**
  * @inheritdoc
  */
 public function handle()
 {
     // older than 10 days
     $builder = Commit::query();
     $builder->where('end_time', '<', time() - self::DAYS * 24 * 3600);
     $builder->where('end_time', '!=', '0');
     $commits = $builder->get();
     /** @var Commit $commit */
     foreach ($commits as $commit) {
         if ($this->option('dry-run')) {
             $this->comment('Remove:' . $commit->id);
             continue;
         }
         $this->info('Remove:' . $commit->id);
         $commit->delete();
     }
 }
コード例 #8
0
ファイル: Scheduler.php プロジェクト: funivan/ci
 /**
  * Execute the console command
  *
  * @return mixed
  */
 public function handle()
 {
     /** @var Commit $inProgressCommit */
     $inProgressCommit = Commit::query()->where('status', '=', Commit::STATUS_IN_PROGRESS)->get()->first();
     if (!empty($inProgressCommit)) {
         $this->getOutput()->writeln('Already check commit: ' . $inProgressCommit->hash);
         return;
     }
     /** @var Commit $commit */
     $commit = Commit::query()->where('status', '=', Commit::STATUS_PENDING)->get()->first();
     if (empty($commit)) {
         $this->getOutput()->writeln('Done');
         return;
     }
     $checker = new \App\Ci\Checker\ScheduledChecker();
     $checker->check($commit);
 }
コード例 #9
0
ファイル: CleanLogs.php プロジェクト: funivan/ci
 /**
  * @inheritdoc
  */
 public function handle()
 {
     // older than 10 days
     $builder = Commit::query();
     $builder->where('end_time', '<', time() - self::DAYS * 24 * 3600);
     $builder->where('end_time', '!=', '0');
     $commits = $builder->get();
     /** @var Commit $commit */
     foreach ($commits as $commit) {
         $file = $commit->getLogFilePath();
         if ($this->option('dry-run')) {
             $this->comment('Remove:' . $file);
             continue;
         }
         if (is_file($file)) {
             $this->info('Remove:' . $file);
             unlink($file);
         }
     }
 }