示例#1
0
 /**
  * @param Build $build
  * @return bool|AbstractProvider
  */
 public static function createForBuild(Build $build)
 {
     switch (strtolower($build->getProject()->getScm())) {
         case 'git':
             $git = new Git();
             if ($build->getForkUri()) {
                 $git->setRepository($build->getForkUri());
             } else {
                 $git->setRepository($build->getProject()->getUri());
             }
             return $git;
     }
     return false;
 }
 /**
  * @param Build $build
  */
 public function generateBuildStatistics(Build $build)
 {
     $statistic = new Build\Statistic();
     $statistic->setName('method-coverage')->setValue($this->details['coveredMethods']);
     $build->addStatistic($statistic);
     $statistic = new Build\Statistic();
     $statistic->setName('statement-coverage')->setValue($this->details['coverageStatements']);
     $build->addStatistic($statistic);
     $statistic = new Build\Statistic();
     $statistic->setName('conditional-coverage')->setValue($this->details['coverageConditionals']);
     $build->addStatistic($statistic);
     $statistic = new Build\Statistic();
     $statistic->setName('total-coverage')->setValue($this->details['coverage']);
     $build->addStatistic($statistic);
     if ($build->getParent()) {
         if (isset($this->details['methodCoverageChange'])) {
             $statistic = new Build\Statistic();
             $statistic->setName('method-coverage-change');
             $statistic->setValue($this->details['methodCoverageChange']);
             $build->addStatistic($statistic);
         }
         if (isset($this->details['statementCoverageChange'])) {
             $statistic = new Build\Statistic();
             $statistic->setName('statement-coverage-change');
             $statistic->setValue($this->details['statementCoverageChange']);
             $build->addStatistic($statistic);
         }
         if (isset($this->details['conditionalCoverageChange'])) {
             $statistic = new Build\Statistic();
             $statistic->setName('conditional-coverage-change');
             $statistic->setValue($this->details['conditionalCoverageChange']);
             $build->addStatistic($statistic);
         }
         if (isset($this->details['totalCoverageChange'])) {
             $statistic = new Build\Statistic();
             $statistic->setName('total-coverage-change');
             $statistic->setValue($this->details['totalCoverageChange']);
             $build->addStatistic($statistic);
             $alert = new Build\Alert();
             $message = 'Code Coverage %s by ' . number_format(abs($this->details['totalCoverageChange']), 2) . '%%';
             if ($this->details['totalCoverageChange'] < 0) {
                 $alert->setType('warning');
                 $alert->setDescription(sprintf($message, 'Decreased'));
             } elseif ($this->details['totalCoverageChange'] > 0) {
                 $alert->setType('success');
                 $alert->setDescription(sprintf($message, 'Increased'));
             } else {
                 $alert->setType('info');
                 $alert->setDescription('Code Coverage Remained the Same');
             }
             $build->addAlert($alert);
         }
     }
 }
示例#3
0
 /**
  * Setup the directory structure needed for the build.
  *
  * @param Build $build
  * @return $this
  */
 protected function setupEnvironment(Build $build)
 {
     $environment = new Environment();
     $environment->setPrivateKey($build->getProject()->getCreatedBy()->getPrivateKey());
     $environment->setUp();
     $this->system->getEventManager()->trigger('build.pre.environment', $build);
     $this->workingDir = $this->buildDirectory . '/' . $build->getProject()->getName() . '/' . $build->getId();
     $this->outputDir = $this->dataDirectory . '/' . $build->getProject()->getName() . '/' . $build->getId();
     if (!file_exists($this->workingDir)) {
         mkdir($this->workingDir, 0775, true);
     }
     if (!file_exists($this->outputDir)) {
         mkdir($this->outputDir, 0775, true);
     }
     $this->outputFile = $this->outputDir . '/console.html';
     touch($this->outputFile);
     $this->log('Working Directory: ' . $this->workingDir);
     $this->scm = ProviderFactory::createForBuild($build);
     $this->scm->setEnvironment($environment);
     $this->scm->setLogFile($this->outputFile);
     $this->system->getEventManager()->trigger('build.post.environment', $build);
     return $this;
 }
 /**
  * Strip off the irrelevant part of the file name (build path) and return the shortened file name.
  *
  * @param string $file
  * @return string
  */
 protected function stripBuildPath($file)
 {
     $base = $this->build->getProject()->getName() . '/' . $this->build->getId();
     return substr($file, strpos($file, $base) + strlen($base) + 1);
 }