Example #1
0
 /**
  * Run CasperJS tests.
  * @return bool
  */
 public function execute()
 {
     $this->phpci->logExecOutput(false);
     $casperJs = $this->phpci->findBinary('casperjs');
     if (!$casperJs) {
         $this->phpci->logFailure(Lang::get('could_not_find', 'casperjs'));
         return false;
     }
     $curdir = getcwd();
     chdir($this->phpci->buildPath);
     $cmd = $casperJs . " test {$this->tests_path} --xunit={$this->x_unit_file_path} {$this->arguments}";
     $success = $this->phpci->executeCommand($cmd);
     chdir($curdir);
     $xUnitString = file_get_contents($this->x_unit_file_path);
     try {
         $xUnitParser = new XUnitParser($xUnitString);
         $output = $xUnitParser->parse();
         $failures = $xUnitParser->getTotalFailures();
     } catch (\Exception $ex) {
         $this->phpci->logFailure($xUnitParser);
         throw $ex;
     }
     $this->build->storeMeta('casperJs-errors', $failures);
     $this->build->storeMeta('casperJs-data', $output);
     $this->phpci->logExecOutput(true);
     return $success;
 }
Example #2
0
 /**
  * Takes a generic build and returns a type-specific build model.
  * @param Build $build The build from which to get a more specific build type.
  * @return Build
  */
 public static function getBuild(Build $build)
 {
     $project = $build->getProject();
     if (!empty($project)) {
         switch ($project->getType()) {
             case 'remote':
                 $type = 'RemoteGitBuild';
                 break;
             case 'local':
                 $type = 'LocalBuild';
                 break;
             case 'github':
                 $type = 'GithubBuild';
                 break;
             case 'bitbucket':
                 $type = 'BitbucketBuild';
                 break;
             case 'gitlab':
                 $type = 'GitlabBuild';
                 break;
             case 'hg':
                 $type = 'MercurialBuild';
                 break;
             case 'svn':
                 $type = 'SubversionBuild';
                 break;
             default:
                 return $build;
         }
         $class = '\\PHPCI\\Model\\Build\\' . $type;
         $build = new $class($build->getDataArray());
     }
     return $build;
 }
Example #3
0
 protected function write(array $record)
 {
     $message = (string) $record['message'];
     $message = str_replace($this->build->currentBuildPath, '/', $message);
     $this->logValue .= $message . PHP_EOL;
     $this->build->setLog($this->logValue);
 }
Example #4
0
 /**
  * Takes a generic build and returns a type-specific build model.
  * @param Build $base The build from which to get a more specific build type.
  * @return Build
  */
 public static function getBuild(Build $base)
 {
     switch ($base->getProject()->getType()) {
         case 'remote':
             $type = 'RemoteGitBuild';
             break;
         case 'local':
             $type = 'LocalBuild';
             break;
         case 'github':
             $type = 'GithubBuild';
             break;
         case 'bitbucket':
             $type = 'BitbucketBuild';
             break;
         case 'gitlab':
             $type = 'GitlabBuild';
             break;
         case 'hg':
             $type = 'MercurialBuild';
             break;
     }
     $type = '\\PHPCI\\Model\\Build\\' . $type;
     return new $type($base->getDataArray());
 }
 /**
  * Standard Constructor
  *
  * $options[<branch>]['env'] Filepath to source environment file.
  * $options[<branch>]['path'] Filepath to destination environment file.
  *
  * @param Builder $phpci
  * @param Build $build
  * @param array $options
  *
  */
 public function __construct(Builder $phpci, Build $build, array $options = [])
 {
     $this->phpci = $phpci;
     $this->build = $build;
     $this->branch = $this->build->getBranch();
     $this->envFilepath = $this->loadEnvPath($options);
     $this->envFilename = $this->loadFilename($options);
 }
Example #6
0
 /**
  * @param array $data
  */
 private function reportErrors(array $data)
 {
     foreach ($data as $test) {
         if ($test['pass']) {
             continue;
         }
         $message = explode('::', $test['message']);
         $this->build->reportError($this->phpci, 'stage_test', sprintf('Test "%s" failed.', $message[1]), BuildError::SEVERITY_CRITICAL, $message[0]);
     }
 }
 /**
  * Setup the test environment.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->builderMock = $this->getMockBuilder('PHPCI\\Builder')->getMock();
     $this->buildMock = $this->getMockBuilder('PHPCI\\Model\\Build')->getMock();
     $this->builderMock->method('log')->willReturn(null);
     $this->builderMock->method('logSuccess')->willReturn(null);
     $this->builderMock->method('logFailure')->willReturn(null);
     $this->buildMock->method('getBranch')->willReturn('master');
 }
Example #8
0
 /**
  * Executes parallel lint
  */
 public function execute()
 {
     list($ignore) = $this->getFlags();
     $phplint = $this->phpci->findBinary('parallel-lint');
     $cmd = $phplint . ' %s "%s"';
     $success = $this->phpci->executeCommand($cmd, $ignore, $this->directory);
     $output = $this->phpci->getLastOutput();
     $matches = array();
     if (preg_match_all('/Parse error\\:/', $output, $matches)) {
         $this->build->storeMeta('phplint-errors', count($matches[0]));
     }
     return $success;
 }
Example #9
0
 /**
  * @param Build $copyFrom
  * @return \PHPCI\Model\Build
  */
 public function createDuplicateBuild(Build $copyFrom)
 {
     $data = $copyFrom->getDataArray();
     // Clean up unwanted properties from the original build:
     unset($data['id']);
     unset($data['status']);
     unset($data['log']);
     unset($data['started']);
     unset($data['finished']);
     $build = new Build();
     $build->setValues($data);
     $build->setCreated(new \DateTime());
     return $this->buildStore->save($build);
 }
Example #10
0
 /**
  *
  * @return bool|null
  * @throws \Exception
  */
 public function execute()
 {
     // No configuration found
     if (empty($this->options)) {
         throw new \Exception('No deployer configuration found, are you sure you added configuration?');
     }
     /** @var array $branchConfiguration */
     $branchConfiguration = $this->_getConfigurationForCurrentBranch();
     // Current Branch does not exist in the configuration, silently ignore
     if ($branchConfiguration === null) {
         return null;
     }
     // Copy the deploy.php if set
     if (isset($this->options['deployFile'])) {
         if ($this->phpci->executeCommand('cp ' . $this->options['deployFile'] . ' ' . $this->build->currentBuildPath . '/deploy.php')) {
             $this->phpci->log('Copied the deploy file successfully.');
         }
     }
     // Validate the yaml configuration and if correct: deploy
     if ($this->_validateDeployerOptions($branchConfiguration)) {
         // Lets deploy...
         $env = 'STAGE=' . $branchConfiguration['stage'] . ' ';
         $env .= 'SERVER=' . $branchConfiguration['server'] . ' ';
         $env .= 'USER='******'user'] . ' ';
         $env .= 'DEPLOY_PATH=' . $branchConfiguration['deploy_path'] . ' ';
         $env .= 'BRANCH=' . $branchConfiguration['branch'] . ' ';
         $env .= 'REPOSITORY=' . $branchConfiguration['repository'] . ' ';
         $env .= 'SHARED_DIRS=' . implode(',', $branchConfiguration['shared_dirs']) . ' ';
         $env .= 'WRITABLE_DIRS=' . implode(',', $branchConfiguration['writable_dirs']) . ' ';
         $env .= 'BUILD=' . $this->build->getId() . ' ';
         try {
             $this->phpci->executeCommand('cd ' . $this->build->currentBuildPath);
             $command = $env . 'dep deploy ' . $branchConfiguration['stage'];
             if ($this->phpci->executeCommand($command)) {
                 $success = true;
             } else {
                 $this->phpci->logFailure('Something went wrong at the deployer part.' . PHP_EOL . 'The following command was used:' . PHP_EOL . $command);
                 $success = false;
             }
         } catch (\Exception $e) {
             $this->phpci->logFailure('Something went wrong at the deployer part.', $e);
             $success = false;
         }
     } else {
         $success = false;
     }
     return $success;
 }
Example #11
0
 /**
  * Run tests from a Codeception config file.
  * @param $configPath
  * @return bool|mixed
  * @throws \Exception
  */
 protected function runConfigFile($configPath)
 {
     $this->phpci->logExecOutput(false);
     $codecept = $this->phpci->findBinary('codecept');
     if (!$codecept) {
         $this->phpci->logFailure(Lang::get('could_not_find', 'codecept'));
         return false;
     }
     $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
     if (IS_WIN) {
         $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
     }
     $configPath = $this->phpci->buildPath . $configPath;
     $success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath);
     $this->phpci->log('Codeception XML path: ' . $this->phpci->buildPath . $this->path . 'report.xml', Loglevel::DEBUG);
     $xml = file_get_contents($this->phpci->buildPath . $this->path . 'report.xml', false);
     $parser = new Parser($this->phpci, $xml);
     $output = $parser->parse();
     $meta = array('tests' => $parser->getTotalTests(), 'timetaken' => $parser->getTotalTimeTaken(), 'failures' => $parser->getTotalFailures());
     $this->build->storeMeta('codeception-meta', $meta);
     $this->build->storeMeta('codeception-data', $output);
     $this->build->storeMeta('codeception-errors', $parser->getTotalFailures());
     $this->phpci->logExecOutput(true);
     return $success;
 }
Example #12
0
 /**
  * Executes phptal lint
  */
 public function execute()
 {
     $this->phpci->quiet = true;
     $this->phpci->logExecOutput(false);
     foreach ($this->directories as $dir) {
         $this->lintDirectory($dir);
     }
     $this->phpci->quiet = false;
     $this->phpci->logExecOutput(true);
     $errors = 0;
     $warnings = 0;
     foreach ($this->failedPaths as $path) {
         if ($path['type'] == 'error') {
             $errors++;
         } else {
             $warnings++;
         }
     }
     $this->build->storeMeta('phptallint-warnings', $warnings);
     $this->build->storeMeta('phptallint-errors', $errors);
     $this->build->storeMeta('phptallint-data', $this->failedPaths);
     $success = true;
     if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) {
         $success = false;
     }
     if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) {
         $success = false;
     }
     return $success;
 }
Example #13
0
 /**
  * Runs PHP Spec tests.
  */
 public function execute()
 {
     $curdir = getcwd();
     chdir($this->phpci->buildPath);
     $phpspec = $this->phpci->findBinary(array('phpspec', 'phpspec.php'));
     if (!$phpspec) {
         $this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpspec'));
         return false;
     }
     $success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
     $output = $this->phpci->getLastOutput();
     chdir($curdir);
     /*
      * process xml output
      *
      * <testsuites time=FLOAT tests=INT failures=INT errors=INT>
      *   <testsuite name=STRING time=FLOAT tests=INT failures=INT errors=INT skipped=INT>
      *     <testcase name=STRING time=FLOAT classname=STRING status=STRING/>
      *   </testsuite>
      * </testsuites
      */
     $xml = new \SimpleXMLElement($output);
     $attr = $xml->attributes();
     $data = array('time' => (double) $attr['time'], 'tests' => (int) $attr['tests'], 'failures' => (int) $attr['failures'], 'errors' => (int) $attr['errors'], 'suites' => array());
     /**
      * @var \SimpleXMLElement $group
      */
     foreach ($xml->xpath('testsuite') as $group) {
         $attr = $group->attributes();
         $suite = array('name' => (string) $attr['name'], 'time' => (double) $attr['time'], 'tests' => (int) $attr['tests'], 'failures' => (int) $attr['failures'], 'errors' => (int) $attr['errors'], 'skipped' => (int) $attr['skipped'], 'cases' => array());
         /**
          * @var \SimpleXMLElement $child
          */
         foreach ($group->xpath('testcase') as $child) {
             $attr = $child->attributes();
             $case = array('name' => (string) $attr['name'], 'classname' => (string) $attr['classname'], 'time' => (double) $attr['time'], 'status' => (string) $attr['status']);
             if ($case['status'] == 'failed') {
                 $error = array();
                 /*
                  * ok, sad, we had an error
                  *
                  * there should be one - foreach makes this easier
                  */
                 foreach ($child->xpath('failure') as $failure) {
                     $attr = $failure->attributes();
                     $error['type'] = (string) $attr['type'];
                     $error['message'] = (string) $attr['message'];
                 }
                 foreach ($child->xpath('system-err') as $system_err) {
                     $error['raw'] = (string) $system_err;
                 }
                 $case['error'] = $error;
             }
             $suite['cases'][] = $case;
         }
         $data['suites'][] = $suite;
     }
     $this->build->storeMeta('phpspec', $data);
     return $success;
 }
Example #14
0
 /**
  * @covers PHPUnit::execute
  */
 public function testExecute_CreateDuplicateBuild()
 {
     $build = new Build();
     $build->setId(1);
     $build->setProject(101);
     $build->setCommitId('abcde');
     $build->setStatus(Build::STATUS_FAILED);
     $build->setLog('Test');
     $build->setBranch('example_branch');
     $build->setStarted(new \DateTime());
     $build->setFinished(new \DateTime());
     $build->setCommitMessage('test');
     $build->setCommitterEmail('*****@*****.**');
     $build->setExtra(json_encode(array('item1' => 1001)));
     $returnValue = $this->testedService->createDuplicateBuild($build);
     $this->assertNotEquals($build->getId(), $returnValue->getId());
     $this->assertEquals($build->getProjectId(), $returnValue->getProjectId());
     $this->assertEquals($build->getCommitId(), $returnValue->getCommitId());
     $this->assertNotEquals($build->getStatus(), $returnValue->getStatus());
     $this->assertEquals(Build::STATUS_NEW, $returnValue->getStatus());
     $this->assertNull($returnValue->getLog());
     $this->assertEquals($build->getBranch(), $returnValue->getBranch());
     $this->assertNotEquals($build->getCreated(), $returnValue->getCreated());
     $this->assertNull($returnValue->getStarted());
     $this->assertNull($returnValue->getFinished());
     $this->assertEquals('test', $returnValue->getCommitMessage());
     $this->assertEquals('*****@*****.**', $returnValue->getCommitterEmail());
     $this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
 }
 /**
  * Runs the shell command.
  */
 public function execute()
 {
     $success = false;
     $successfulBuild = $this->build->isSuccessful();
     if ($successfulBuild) {
         $success = $this->callDeploymentUrl($this->deployUrl, $this->requestMethod);
     }
     return $success;
 }
 /**
  * Report all of the errors we've encountered line-by-line.
  * @param $output
  */
 protected function reportErrors($output)
 {
     foreach ($output as $error) {
         $message = 'Class ' . $error['class'] . ' does not have a Docblock comment.';
         if ($error['type'] == 'method') {
             $message = 'Method ' . $error['class'] . '::' . $error['method'] . ' does not have a Docblock comment.';
         }
         $this->build->reportError($this->phpci, $error['file'], $error['line'], $message);
     }
 }
Example #17
0
 /**
  * Report all of the errors we've encountered line-by-line.
  * @param $output
  */
 protected function reportErrors($output)
 {
     foreach ($output as $error) {
         $message = 'Class ' . $error['class'] . ' is missing a docblock.';
         $severity = PHPCI\Model\BuildError::SEVERITY_LOW;
         if ($error['type'] == 'method') {
             $message = $error['class'] . '::' . $error['method'] . ' is missing a docblock.';
             $severity = PHPCI\Model\BuildError::SEVERITY_NORMAL;
         }
         $this->build->reportError($this->phpci, 'php_docblock_checker', $message, $severity, $error['file'], $error['line']);
     }
 }
Example #18
0
 /**
  * Pulls all pending builds from the database and runs them.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $parser = new Parser();
     $yaml = file_get_contents(APPLICATION_PATH . 'PHPCI/config.yml');
     $this->settings = $parser->parse($yaml);
     $token = $this->settings['phpci']['github']['token'];
     if (!$token) {
         $this->logger->error(Lang::get('no_token'));
         return;
     }
     $buildStore = Factory::getStore('Build');
     $this->logger->addInfo(Lang::get('finding_projects'));
     $projectStore = Factory::getStore('Project');
     $result = $projectStore->getWhere();
     $this->logger->addInfo(Lang::get('found_n_projects', count($result['items'])));
     foreach ($result['items'] as $project) {
         $http = new HttpClient('https://api.github.com');
         $commits = $http->get('/repos/' . $project->getReference() . '/commits', array('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(Lang::get('last_commit_is', $project->getTitle(), $last_commit));
         if ($project->getLastCommit() != $last_commit && $last_commit != "") {
             $this->logger->info(Lang::get('adding_new_build'));
             $build = new Build();
             $build->setProjectId($project->getId());
             $build->setCommitId($last_commit);
             $build->setStatus(Build::STATUS_NEW);
             $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(Lang::get('finished_processing_builds'));
 }
 /**
  * @param $configId
  * @param bool $setProject
  * @return Build
  */
 protected function getBuild($configId, $setProject = true)
 {
     $config = array('1' => array('status' => Build::STATUS_RUNNING, 'id' => 77, 'finishDateTime' => null, 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => null), '2' => array('status' => Build::STATUS_RUNNING, 'id' => 78, 'finishDateTime' => null, 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => 4), '3' => array('status' => Build::STATUS_SUCCESS, 'id' => 7, 'finishDateTime' => '2014-10-25 21:50:02', 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => null), '4' => array('status' => Build::STATUS_FAILED, 'id' => 13, 'finishDateTime' => '2014-10-13 13:13:13', 'previousBuild' => null), '5' => array('status' => Build::STATUS_NEW, 'id' => 1000, 'finishDateTime' => '2014-12-25 21:12:21', 'previousBuild' => 3));
     $build = new Build();
     $build->setId($config[$configId]['id']);
     $build->setBranch(self::BRANCH);
     $build->setStatus($config[$configId]['status']);
     if ($config[$configId]['finishDateTime']) {
         $build->setFinished(new \DateTime($config[$configId]['finishDateTime']));
     }
     if (!empty($config[$configId]['startedDate'])) {
         $build->setStarted(new \DateTime('2014-10-25 21:20:02'));
     }
     $project = $this->getProjectMock($config[$configId]['previousBuild'], $setProject);
     $build->setProjectObject($project);
     return $build;
 }
Example #20
0
 /**
  * @covers PHPUnit::execute
  */
 public function testExecute_TestBuildExtra()
 {
     $info = array('item1' => 'Item One', 'item2' => 2);
     $build = new Build();
     $build->setExtra(json_encode($info));
     $this->assertEquals('Item One', $build->getExtra('item1'));
     $this->assertEquals(2, $build->getExtra('item2'));
     $this->assertNull($build->getExtra('item3'));
     $this->assertEquals($info, $build->getExtra());
 }
Example #21
0
 /**
  * Runs PHP Mess Detector in a specified directory.
  */
 public function execute()
 {
     if (!$this->tryAndProcessRules()) {
         return false;
     }
     $phpmdBinaryPath = $this->phpci->findBinary('phpmd');
     if (!$phpmdBinaryPath) {
         $this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpmd'));
         return false;
     }
     $this->executePhpMd($phpmdBinaryPath);
     list($errorCount, $data) = $this->processReport(trim($this->phpci->getLastOutput()));
     $this->build->storeMeta('phpmd-warnings', $errorCount);
     $this->build->storeMeta('phpmd-data', $data);
     return $this->wasLastExecSuccessful($errorCount);
 }
Example #22
0
 /**
  * Get the list of email addresses to send to.
  * @return array
  */
 protected function getEmailAddresses()
 {
     $addresses = array();
     $committer = $this->build->getCommitterEmail();
     if (isset($this->options['committer']) && !empty($committer)) {
         $addresses[] = $committer;
     }
     if (isset($this->options['addresses'])) {
         foreach ($this->options['addresses'] as $address) {
             $addresses[] = $address;
         }
     }
     if (empty($addresses) && isset($this->options['default_mailto_address'])) {
         $addresses[] = $this->options['default_mailto_address'];
     }
     return array_unique($addresses);
 }
Example #23
0
 /**
  * Process PHPMD's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process PHPMD report XML.');
     }
     $warnings = 0;
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->violation as $violation) {
             $warnings++;
             $this->build->reportError($this->phpci, 'php_mess_detector', (string) $violation, PHPCI\Model\BuildError::SEVERITY_HIGH, $fileName, (int) $violation['beginline'], (int) $violation['endline']);
         }
     }
     return $warnings;
 }
Example #24
0
 /**
  * Create a new pending build for a project.
  */
 public function build($projectId)
 {
     /* @var \PHPCI\Model\Project $project */
     $project = $this->projectStore->getById($projectId);
     if (empty($project)) {
         throw new NotFoundException('Project with id: ' . $projectId . ' not found');
     }
     $build = new Build();
     $build->setProjectId($projectId);
     $build->setCommitId('Manual');
     $build->setStatus(Build::STATUS_NEW);
     $build->setBranch($project->getBranch());
     $build->setCreated(new \DateTime());
     $build->setCommitterEmail($_SESSION['user']->getEmail());
     $build = $this->buildStore->save($build);
     header('Location: ' . PHPCI_URL . 'build/view/' . $build->getId());
     exit;
 }
Example #25
0
 /**
  * Set up a working copy of the project for building.
  */
 protected function setupBuild()
 {
     $this->buildPath = $this->build->getBuildPath();
     $this->interpolator->setupInterpolationVars($this->build, $this->buildPath, PHPCI_URL);
     $this->commandExecutor->setBuildPath($this->buildPath);
     // Create a working copy of the project:
     if (!$this->build->createWorkingCopy($this, $this->buildPath)) {
         throw new \Exception(Lang::get('could_not_create_working'));
     }
     // Does the project's phpci.yml request verbose mode?
     if (!isset($this->config['build_settings']['verbose']) || !$this->config['build_settings']['verbose']) {
         $this->verbose = false;
     }
     // Does the project have any paths it wants plugins to ignore?
     if (isset($this->config['build_settings']['ignore'])) {
         $this->ignore = $this->config['build_settings']['ignore'];
     }
     $this->buildLogger->logSuccess(Lang::get('working_copy_created', $this->buildPath));
     return true;
 }
Example #26
0
 /**
  * Pulls all pending builds from the database and runs them.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $parser = new Parser();
     $yaml = file_get_contents(APPLICATION_PATH . 'PHPCI/config.yml');
     $this->settings = $parser->parse($yaml);
     $token = $this->settings['phpci']['github']['token'];
     if (!$token) {
         $this->logger->error("No github token found");
         exit;
     }
     $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', array('access_token' => $token));
         $last_commit = $commits['body'][0]['sha'];
         $last_committer = $commits['body'][0]['commit']['committer']['email'];
         $this->logger->info("Last commit to github for " . $project->getTitle() . " is " . $last_commit);
         if ($project->getLastCommit() != $last_commit && $last_commit != "") {
             $this->logger->info("Last commit is different from database, adding new build for " . $project->getTitle());
             $build = new Build();
             $build->setProjectId($project->getId());
             $build->setCommitId($last_commit);
             $build->setStatus(Build::STATUS_NEW);
             $build->setBranch($project->getBranch());
             $build->setCreated(new \DateTime());
             if (!empty($last_committer)) {
                 $build->setCommitterEmail($last_committer);
             }
             $buildStore->save($build);
             $project->setLastCommit($last_commit);
             $projectStore->save($project);
         }
     }
     $this->logger->addInfo("Finished processing builds");
 }
Example #27
0
 /**
  * Process PHPMD's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process PHPMD report XML.');
     }
     $warnings = 0;
     $data = array();
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->violation as $violation) {
             $warnings++;
             $warning = array('file' => $fileName, 'line_start' => (int) $violation['beginline'], 'line_end' => (int) $violation['endline'], 'rule' => (string) $violation['rule'], 'ruleset' => (string) $violation['ruleset'], 'priority' => (int) $violation['priority'], 'message' => (string) $violation);
             $this->build->reportError($this->phpci, $fileName, (int) $violation['beginline'], (string) $violation);
             $data[] = $warning;
         }
     }
     return array($warnings, $data);
 }
Example #28
0
 /**
  * Process JSHint's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process JSHint report XML.');
     }
     $warnings = 0;
     $data = array();
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->error as $error) {
             $warnings++;
             $warning = array('file' => $fileName, 'line' => (int) $error['line'], 'severity' => (string) $error['severity'], 'message' => (string) $error['message']);
             $this->build->reportError($this->phpci, $fileName, (int) $error['line'], (string) $error['message']);
             $data[] = $warning;
         }
     }
     return array($warnings, $data);
 }
Example #29
0
 /**
  * Runs PHP Mess Detector in a specified directory.
  */
 public function execute()
 {
     // Check that the binary exists:
     $checker = $this->phpci->findBinary('phpdoccheck');
     if (!$checker) {
         $this->phpci->logFailure('Could not find phpdoccheck.');
         return false;
     }
     // Build ignore string:
     $ignore = '';
     if (count($this->ignore)) {
         $ignore = ' --exclude="' . implode(',', $this->ignore) . '"';
     }
     // Are we skipping any checks?
     $add = '';
     if ($this->skipClasses) {
         $add .= ' --skip-classes';
     }
     if ($this->skipMethods) {
         $add .= ' --skip-methods';
     }
     // Build command string:
     $path = $this->phpci->buildPath . $this->path;
     $cmd = $checker . ' --json --directory="%s"%s%s';
     // Disable exec output logging, as we don't want the XML report in the log:
     $this->phpci->logExecOutput(false);
     // Run checker:
     $this->phpci->executeCommand($cmd, $path, $ignore, $add);
     // Re-enable exec output logging:
     $this->phpci->logExecOutput(true);
     $output = json_decode($this->phpci->getLastOutput());
     $errors = count($output);
     $success = true;
     $this->build->storeMeta('phpdoccheck-warnings', $errors);
     $this->build->storeMeta('phpdoccheck-data', $output);
     if ($this->allowed_warnings != -1 && $errors > $this->allowed_warnings) {
         $success = false;
     }
     return $success;
 }
Example #30
0
 /**
  * {@inheritDoc}
  */
 public function execute()
 {
     $success = true;
     $this->phpci->logExecOutput(false);
     // Run any config files first. This can be either a single value or an array
     if ($this->configFile !== null) {
         $success &= $this->runConfigFile($this->configFile);
     }
     $tapString = file_get_contents($this->phpci->buildPath . $this->logPath . DIRECTORY_SEPARATOR . 'report.tap.log');
     try {
         $tapParser = new TapParser($tapString);
         $output = $tapParser->parse();
     } catch (\Exception $ex) {
         $this->phpci->logFailure($tapString);
         throw $ex;
     }
     $failures = $tapParser->getTotalFailures();
     $this->build->storeMeta('codeception-errors', $failures);
     $this->build->storeMeta('codeception-data', $output);
     $this->phpci->logExecOutput(true);
     return $success;
 }