Beispiel #1
0
 /**
  * Runs PHP Copy/Paste Detector in a specified directory.
  */
 public function execute()
 {
     $ignore = '';
     if (count($this->phpci->ignore)) {
         $map = function ($item) {
             return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item);
         };
         $ignore = array_map($map, $this->phpci->ignore);
         $ignore = implode('', $ignore);
     }
     $phploc = $this->phpci->findBinary('phploc');
     if (!$phploc) {
         $this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phploc'));
         return false;
     }
     $success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
     $output = $this->phpci->getLastOutput();
     if (preg_match_all('/\\((LOC|CLOC|NCLOC|LLOC)\\)\\s+([0-9]+)/', $output, $matches)) {
         $data = array();
         foreach ($matches[1] as $k => $v) {
             $data[$v] = (int) $matches[2][$k];
         }
         $this->build->storeMeta('phploc', $data);
     }
     return $success;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Runs Pdepend with the given criteria as arguments
  */
 public function execute()
 {
     if (!is_writable($this->location)) {
         throw new \Exception(sprintf('The location %s is not writable.', $this->location));
     }
     $pdepend = $this->phpci->findBinary('pdepend');
     if (!$pdepend) {
         $this->phpci->logFailure('Could not find pdepend.');
         return false;
     }
     $cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
     $this->removeBuildArtifacts();
     // If we need to ignore directories
     if (count($this->phpci->ignore)) {
         $ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
     } else {
         $ignore = '';
     }
     $success = $this->phpci->executeCommand($cmd, $this->location . DIRECTORY_SEPARATOR . $this->summary, $this->location . DIRECTORY_SEPARATOR . $this->chart, $this->location . DIRECTORY_SEPARATOR . $this->pyramid, $ignore, $this->directory);
     $config = $this->phpci->getSystemConfig('phpci');
     if ($success) {
         $this->phpci->logSuccess(sprintf("Pdepend successful. You can use %s\n, ![Chart](%s \"Pdepend Chart\")\n\n                    and ![Pyramid](%s \"Pdepend Pyramid\")\n\n                    for inclusion in the readme.md file", $config['url'] . '/build/pdepend/' . $this->summary, $config['url'] . '/build/pdepend/' . $this->chart, $config['url'] . '/build/pdepend/' . $this->pyramid));
     } else {
         $this->phpci->logFailure(sprintf("The function '%s' failed"));
     }
     return $success;
 }
Beispiel #4
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;
 }
Beispiel #5
0
 /**
  * Run PHP CS Fixer.
  * @return bool
  */
 public function execute()
 {
     $curdir = getcwd();
     chdir($this->workingdir);
     $phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
     $cmd = $phpcsfixer . ' fix . %s %s %s';
     $success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
     chdir($curdir);
     return $success;
 }
Beispiel #6
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('Could not find phpspec.');
         return false;
     }
     $success = $this->phpci->executeCommand($phpspec . ' --format=pretty --no-code-generation run');
     chdir($curdir);
     return $success;
 }
Beispiel #7
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;
 }
Beispiel #8
0
 /**
  * Runs the shell command.
  */
 public function execute()
 {
     if (!defined('ENABLE_SHELL_PLUGIN') || !ENABLE_SHELL_PLUGIN) {
         throw new \Exception('The shell plugin is not enabled.');
     }
     $success = true;
     foreach ($this->commands as $command) {
         $command = $this->phpci->interpolate($command);
         if (!$this->phpci->executeCommand($command)) {
             $success = false;
         }
     }
     return $success;
 }
Beispiel #9
0
 /**
  * Run PHP CS Fixer.
  * @return bool
  */
 public function execute()
 {
     $curdir = getcwd();
     chdir($this->workingdir);
     $phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
     if (!$phpcsfixer) {
         $this->phpci->logFailure(Lang::get('could_not_find', 'php-cs-fixer'));
         return false;
     }
     $cmd = $phpcsfixer . ' fix . %s %s %s';
     $success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
     chdir($curdir);
     return $success;
 }
Beispiel #10
0
 /**
  * Wipes a directory's contents
  */
 public function execute()
 {
     $build = $this->phpci->buildPath;
     if ($this->directory == $build || empty($this->directory)) {
         return true;
     }
     if (is_dir($this->directory)) {
         $cmd = 'rm -Rf "%s"';
         if (IS_WIN) {
             $cmd = 'rmdir /S /Q "%s"';
         }
         return $this->phpci->executeCommand($cmd, $this->directory);
     }
     return true;
 }
Beispiel #11
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;
 }
Beispiel #12
0
 /**
  * Run phptal lint against a specific file.
  * @param $path
  * @return bool
  */
 protected function lintFile($path)
 {
     $success = true;
     list($suffixes, $tales) = $this->getFlags();
     $lint = dirname(__FILE__) . '/../../vendor/phptal/phptal/tools/phptal_lint.php';
     $cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"';
     $this->phpci->executeCommand($cmd, $suffixes, $tales, $this->phpci->buildPath . $path);
     $output = $this->phpci->getLastOutput();
     if (preg_match('/Found (.+?) (error|warning)/i', $output, $matches)) {
         $rows = explode(PHP_EOL, $output);
         unset($rows[0]);
         unset($rows[1]);
         unset($rows[2]);
         unset($rows[3]);
         foreach ($rows as $row) {
             $name = basename($path);
             $row = str_replace('(use -i to include your custom modifier functions)', '', $row);
             $message = str_replace($name . ': ', '', $row);
             $parts = explode(' (line ', $message);
             $message = trim($parts[0]);
             $line = str_replace(')', '', $parts[1]);
             $this->failedPaths[] = array('file' => $path, 'line' => $line, 'type' => $matches[2], 'message' => $message);
         }
         $success = false;
     }
     return $success;
 }
Beispiel #13
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;
 }
Beispiel #14
0
 /**
  * Runs PHP Code Sniffer in a specified directory, to a specified standard.
  */
 public function execute()
 {
     list($ignore, $standard, $suffixes) = $this->getFlags();
     $phpcs = $this->phpci->findBinary('phpcs');
     if (!$phpcs) {
         $this->phpci->logFailure('Could not find phpcs.');
         return false;
     }
     $this->phpci->logExecOutput(false);
     $cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
     $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $this->tab_width, $this->encoding, $this->phpci->buildPath . $this->path);
     $output = $this->phpci->getLastOutput();
     list($errors, $warnings, $data) = $this->processReport($output);
     $this->phpci->logExecOutput(true);
     $success = true;
     $this->build->storeMeta('phpcs-warnings', $warnings);
     $this->build->storeMeta('phpcs-errors', $errors);
     $this->build->storeMeta('phpcs-data', $data);
     if ($this->allowed_warnings != -1 && $warnings > $this->allowed_warnings) {
         $success = false;
     }
     if ($this->allowed_errors != -1 && $errors > $this->allowed_errors) {
         $success = false;
     }
     return $success;
 }
Beispiel #15
0
 protected function runConfigFile($configPath)
 {
     if (is_array($configPath)) {
         return $this->recurseArg($configPath, array($this, "runConfigFile"));
     } else {
         $codecept = $this->phpci->findBinary('codecept');
         if (!$codecept) {
             $this->phpci->logFailure('Could not find codeception.');
             return false;
         }
         $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" ' . $this->args;
         if (IS_WIN) {
             $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" ' . $this->args;
         }
         $configPath = $this->phpci->buildPath . $configPath;
         $success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath);
         return $success;
     }
 }
Beispiel #16
0
 /**
  * Execute JSHint.
  * @param $binaryPath
  */
 protected function executeJsHint($binaryPath)
 {
     $cmd = $binaryPath . ' %s --reporter checkstyle';
     $path = $this->getTargetPath();
     // Disable exec output logging, as we don't want the XML report in the log:
     $this->phpci->logExecOutput(false);
     // Run JSHint:
     $this->phpci->executeCommand($cmd, $path);
     // Re-enable exec output logging:
     $this->phpci->logExecOutput(true);
 }
Beispiel #17
0
 /**
  * Handle post-clone tasks (switching branch, etc.)
  * @param Builder $builder
  * @param $cloneTo
  * @return bool
  */
 protected function postCloneSetup(Builder $builder, $cloneTo)
 {
     $success = true;
     $commit = $this->getCommitId();
     // Allow switching to a specific branch:
     if (!empty($commit) && $commit != 'Manual') {
         $cmd = 'cd "%s" && hg checkout %s';
         $success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch());
     }
     return $success;
 }
Beispiel #18
0
 protected function handleBareRepository(Builder $builder, $reference, $buildPath)
 {
     $gitConfig = parse_ini_file($reference . '/config', true);
     // If it is indeed a bare repository, then extract it into our build path:
     if ($gitConfig['core']['bare']) {
         $cmd = 'mkdir %2$s; git --git-dir="%1$s" archive %3$s | tar -x -C "%2$s"';
         $builder->executeCommand($cmd, $reference, $buildPath, $this->getBranch());
         return true;
     }
     return false;
 }
Beispiel #19
0
 /**
  * Runs PHP Copy/Paste Detector in a specified directory.
  */
 public function execute()
 {
     $ignore = '';
     if (count($this->phpci->ignore)) {
         $map = function ($item) {
             return ' --exclude ' . rtrim($item, DIRECTORY_SEPARATOR);
         };
         $ignore = array_map($map, $this->phpci->ignore);
         $ignore = implode('', $ignore);
     }
     $phploc = $this->phpci->findBinary('phploc');
     $success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
     $output = $this->phpci->getLastOutput();
     if (preg_match_all('/\\((LOC|CLOC|NCLOC|LLOC)\\)\\s+([0-9]+)/', $output, $matches)) {
         $data = array();
         foreach ($matches[1] as $k => $v) {
             $data[$v] = (int) $matches[2][$k];
         }
         $this->build->storeMeta('phploc', $data);
     }
     return $success;
 }
Beispiel #20
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $curdir = getcwd();
     chdir($this->phpci->buildPath);
     if (!is_file($this->configFile)) {
         $this->phpci->logFailure(sprintf('The Atoum config file "%s" is missing.', $this->configFile));
         chdir($curdir);
         return false;
     }
     $this->phpci->logExecOutput(false);
     $status = $this->phpci->executeCommand('php %s -c %s -ft -utr', $this->executable, $this->configFile);
     $this->phpci->logExecOutput(true);
     try {
         $parser = new TapParser(mb_convert_encoding('TAP version 13' . PHP_EOL . $this->phpci->getLastOutput(), 'UTF-8', 'ISO-8859-1'));
         $data = $parser->parse();
         $this->reportErrors($data);
     } catch (\Exception $exception) {
         $status = false;
         $this->phpci->logFailure('Impossible to parse the Atoum output.', $exception);
     }
     chdir($curdir);
     return $status;
 }
Beispiel #21
0
 /**
  * @param string $query
  * @return boolean
  * @throws \Exception
  */
 protected function executeFile($query)
 {
     if (!isset($query['file'])) {
         throw new \Exception("Import statement must contain a 'file' key");
     }
     $import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']);
     if (!is_readable($import_file)) {
         throw new \Exception("Cannot open SQL import file: {$import_file}");
     }
     $database = isset($query['database']) ? $this->phpci->interpolate($query['database']) : null;
     $import_command = $this->getImportCommand($import_file, $database);
     if (!$this->phpci->executeCommand($import_command)) {
         throw new \Exception("Unable to execute SQL file");
     }
     return true;
 }
Beispiel #22
0
 /**
  * @param string $query
  * @return boolean
  * @throws \Exception
  */
 protected function executeFile($query)
 {
     if (!isset($query['file'])) {
         throw new \Exception(Lang::get('import_file_key'));
     }
     $import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']);
     if (!is_readable($import_file)) {
         throw new \Exception(Lang::get('cannot_open_import', $import_file));
     }
     $database = isset($query['database']) ? $this->phpci->interpolate($query['database']) : null;
     $import_command = $this->getImportCommand($import_file, $database);
     if (!$this->phpci->executeCommand($import_command)) {
         throw new \Exception(Lang::get('unable_to_execute'));
     }
     return true;
 }
Beispiel #23
0
 /**
  * Execute PHP Mess Detector.
  * @param $binaryPath
  */
 protected function executePhpMd($binaryPath)
 {
     $cmd = $binaryPath . ' "%s" xml %s %s %s';
     $path = $this->getTargetPath();
     $ignore = '';
     if (count($this->ignore)) {
         $ignore = ' --exclude ' . implode(',', $this->ignore);
     }
     $suffixes = '';
     if (count($this->suffixes)) {
         $suffixes = ' --suffixes ' . implode(',', $this->suffixes);
     }
     // Disable exec output logging, as we don't want the XML report in the log:
     $this->phpci->logExecOutput(false);
     // Run PHPMD:
     $this->phpci->executeCommand($cmd, $path, implode(',', $this->rules), $ignore, $suffixes);
     // Re-enable exec output logging:
     $this->phpci->logExecOutput(true);
 }
 /**
  * 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(PHPCI\Helper\Lang::get('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(), true);
     $errors = count($output);
     $success = true;
     $this->build->storeMeta('phpdoccheck-warnings', $errors);
     $this->build->storeMeta('phpdoccheck-data', $output);
     $this->reportErrors($output);
     if ($this->allowed_warnings != -1 && $errors > $this->allowed_warnings) {
         $success = false;
     }
     return $success;
 }
Beispiel #25
0
 /**
  * Use an mercurial clone.
  */
 protected function cloneByHttp(Builder $builder, $cloneTo)
 {
     return $builder->executeCommand('hg clone %s "%s" -r %s', $this->getCloneUrl(), $cloneTo, $this->getBranch());
 }
Beispiel #26
0
 /**
  * Handle any post-clone tasks, like switching branches.
  * @param Builder $builder
  * @param $cloneTo
  * @return bool
  */
 protected function postCloneSetup(Builder $builder, $cloneTo)
 {
     $success = true;
     $commit = $this->getCommitId();
     $chdir = IS_WIN ? 'cd /d "%s"' : 'cd "%s"';
     if (!empty($commit) && $commit != 'Manual') {
         $cmd = $chdir . ' && git checkout %s --quiet';
         $success = $builder->executeCommand($cmd, $cloneTo, $commit);
     }
     // Always update the commit hash with the actual HEAD hash
     if ($builder->executeCommand($chdir . ' && git rev-parse HEAD', $cloneTo)) {
         $this->setCommitId(trim($builder->getLastOutput()));
     }
     return $success;
 }
Beispiel #27
0
 /**
  * Uses git diff to figure out what the diff line position is, based on the error line number.
  * @param Builder $builder
  * @param $file
  * @param $line
  * @return int|null
  */
 protected function getDiffLineNumber(Builder $builder, $file, $line)
 {
     $line = (int) $line;
     $builder->logExecOutput(false);
     $prNumber = $this->getExtra('pull_request_number');
     $path = $builder->buildPath;
     if (!empty($prNumber)) {
         $builder->executeCommand('cd %s && git diff origin/%s "%s"', $path, $this->getBranch(), $file);
     } else {
         $commitId = $this->getCommitId();
         $compare = $commitId == 'Manual' ? 'HEAD' : $commitId;
         $builder->executeCommand('cd %s && git diff %s^^ "%s"', $path, $compare, $file);
     }
     $builder->logExecOutput(true);
     $diff = $builder->getLastOutput();
     $helper = new Diff();
     $lines = $helper->getLinePositions($diff);
     return isset($lines[$line]) ? $lines[$line] : null;
 }
Beispiel #28
0
 /**
  * Use an SSH-based svn export.
  */
 protected function cloneBySsh(Builder $builder, $cloneTo)
 {
     $cmd = $this->svnCommand . ' %s "%s"';
     if (!IS_WIN) {
         $keyFile = $this->writeSshKey($cloneTo);
         $sshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
         $cmd = 'export SVN_SSH="' . $sshWrapper . '" && ' . $cmd;
     }
     $success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo);
     if (!IS_WIN) {
         // Remove the key file and svn wrapper:
         unlink($keyFile);
         unlink($sshWrapper);
     }
     return $success;
 }
Beispiel #29
0
 /**
  * Handle any post-clone tasks, like applying a pull request patch on top of the branch.
  * @param Builder $builder
  * @param $cloneTo
  * @return bool
  */
 protected function postCloneSetup(Builder $builder, $cloneTo)
 {
     $buildType = $this->getExtra('build_type');
     $success = true;
     try {
         if (!empty($buildType) && $buildType == 'pull_request') {
             $remoteUrl = $this->getExtra('remote_url');
             $remoteBranch = $this->getExtra('remote_branch');
             $cmd = 'cd "%s" && git checkout -b phpci/' . $this->getId() . ' %s && git pull -q --no-edit %s %s';
             $success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch(), $remoteUrl, $remoteBranch);
         }
     } catch (\Exception $ex) {
         $success = false;
     }
     if ($success) {
         $success = parent::postCloneSetup($builder, $cloneTo);
     }
     return $success;
 }
Beispiel #30
0
 /**
  * Uses git diff to figure out what the diff line position is, based on the error line number.
  * @param Builder $builder
  * @param $file
  * @param $line
  * @return int|null
  */
 protected function getDiffLineNumber(Builder $builder, $file, $line)
 {
     $builder->logExecOutput(false);
     $prNumber = $this->getExtra('pull_request_number');
     $path = $builder->buildPath;
     if (!empty($prNumber)) {
         $builder->executeCommand('cd %s && git diff origin/%s "%s"', $path, $this->getBranch(), $file);
     } else {
         $builder->executeCommand('cd %s && git diff %s^! "%s"', $path, $this->getCommitId(), $file);
     }
     $builder->logExecOutput(true);
     $diff = $builder->getLastOutput();
     $helper = new Diff();
     $lines = $helper->getLinePositions($diff);
     return $lines[$line];
 }