From 3a59b66d7803670cef5f0850a193750ed418b18c Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 23 May 2017 23:01:31 +0700 Subject: [PATCH] Removed PollCommand. --- src/PHPCensor/Command/PollCommand.php | 95 --------------------------- src/PHPCensor/Console/Application.php | 2 - 2 files changed, 97 deletions(-) delete mode 100644 src/PHPCensor/Command/PollCommand.php diff --git a/src/PHPCensor/Command/PollCommand.php b/src/PHPCensor/Command/PollCommand.php deleted file mode 100644 index 6901369c..00000000 --- a/src/PHPCensor/Command/PollCommand.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ -class PollCommand extends Command -{ - /** - * @var \Monolog\Logger - */ - protected $logger; - - public function __construct(Logger $logger, $name = null) - { - parent::__construct($name); - $this->logger = $logger; - } - - protected function configure() - { - $this - ->setName('php-censor:poll-github') - ->setDescription('Poll GitHub to check if we need to start a build.'); - } - - /** - * Pulls all pending builds from the database and runs them. - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $parser = new Parser(); - $yaml = file_get_contents(APP_DIR . 'config.yml'); - $this->settings = $parser->parse($yaml); - - $token = $this->settings['php-censor']['github']['token']; - - if (!$token) { - $this->logger->error('No GitHub token found'); - return; - } - - $buildStore = Factory::getStore('Build'); - - $this->logger->addInfo('Finding projects to poll'); - $projectStore = Factory::getStore('Project'); - $result = $projectStore->getWhere(); - $this->logger->addInfo(sprintf('Found %d projects', count($result['items']))); - - foreach ($result['items'] as $project) { - $http = new HttpClient('https://api.github.com'); - $commits = $http->get('/repos/' . $project->getReference() . '/commits', ['access_token' => $token]); - - $last_commit = $commits['body'][0]['sha']; - $last_committer = $commits['body'][0]['commit']['committer']['email']; - $message = $commits['body'][0]['commit']['message']; - - $this->logger->info(sprintf('Last commit to GitHub for %s is %s', $project->getTitle(), $last_commit)); - - if (!$project->getArchived() && ($project->getLastCommit() != $last_commit && $last_commit != "")) { - $this->logger->info('Last commit is different to database, adding new build.'); - - $build = new Build(); - $build->setProjectId($project->getId()); - $build->setCommitId($last_commit); - $build->setStatus(Build::STATUS_PENDING); - $build->setBranch($project->getBranch()); - $build->setCreated(new \DateTime()); - $build->setCommitMessage($message); - - if (!empty($last_committer)) { - $build->setCommitterEmail($last_committer); - } - $buildStore->save($build); - - $project->setLastCommit($last_commit); - $projectStore->save($project); - } - } - - $this->logger->addInfo('Finished processing builds.'); - } -} diff --git a/src/PHPCensor/Console/Application.php b/src/PHPCensor/Console/Application.php index 6b407f92..90480150 100644 --- a/src/PHPCensor/Console/Application.php +++ b/src/PHPCensor/Console/Application.php @@ -7,7 +7,6 @@ use b8\Store\Factory; use PHPCensor\Command\CreateAdminCommand; use PHPCensor\Command\CreateBuildCommand; use PHPCensor\Command\InstallCommand; -use PHPCensor\Command\PollCommand; use PHPCensor\Command\RebuildCommand; use PHPCensor\Command\RebuildQueueCommand; use PHPCensor\Command\RunCommand; @@ -105,7 +104,6 @@ class Application extends BaseApplication $this->add(new RunCommand($loggerConfig->getFor('RunCommand'))); $this->add(new RebuildCommand($loggerConfig->getFor('RunCommand'))); $this->add(new InstallCommand()); - $this->add(new PollCommand($loggerConfig->getFor('PollCommand'))); $this->add(new CreateAdminCommand($userStore)); $this->add(new CreateBuildCommand($projectStore, new BuildService($buildStore))); $this->add(new WorkerCommand($loggerConfig->getFor('WorkerCommand')));