Exemplo n.º 1
0
 /**
  * @test
  */
 public function getCommitCountWithTypeDoesNotReturnWrongTopicCommitCount()
 {
     $commit = new \Mrimann\CoMo\Domain\Model\Commit();
     $commit->setCommitLine('[BUGFIX] foo bar');
     $this->fixture->addCommit($commit);
     $this->assertEquals(0, $this->fixture->getCommitCountByType('feature'));
 }
 /**
  * Extracts the commits of a repository, that are not yet extracted and put into the database.
  *
  * @param \Mrimann\CoMo\Domain\Model\Repository $repository
  * @return mixed
  */
 protected function extractCommits(\Mrimann\CoMo\Domain\Model\Repository $repository)
 {
     // Fetch all commits since the last run (or full log if nothing done yet)
     unset($output);
     $lastProcessedCommit = $repository->getLastProcessedCommit();
     // use the --git-dir parameter for git log in case it's a local repository
     $gitDirectory = '';
     if ($repository->isLocalRepository()) {
         $gitDirectory = '--git-dir ' . substr(substr($repository->getUrl(), 7), 0);
     }
     // check if there are commits at all (to avoid nasty CLI output in case we hit
     // an empty repository without any commits in it)
     $noCommitsYetOutput = array();
     $noCommitsYetExitCode = 0;
     @exec('git ' . $gitDirectory . ' log -n 1 > /dev/null 2>&1', $noCommitsYetOutput, $noCommitsYetExitCode);
     if ($noCommitsYetExitCode > 0) {
         $this->outputLine('-> seen an empty repository without any commit at all, skipping!');
         return '';
     }
     $logRange = '';
     if ($lastProcessedCommit != '') {
         $this->outputLine('-> there are commits already, extracting since ' . substr($lastProcessedCommit, 0, 8));
         $logRange = $lastProcessedCommit . '..HEAD';
     } else {
         // check if there's a limit of days to fetch the history from the git log
         if (isset($this->settings['maxDaysToFetchFromGitLogHistory']) && $this->settings['maxDaysToFetchFromGitLogHistory'] > 0) {
             $this->outputLine('-> Limit of max %d days to fetch is in effect, nothing older than that will be extracted', array($this->settings['maxDaysToFetchFromGitLogHistory']));
             $oldestDate = new \DateTime('now -' . $this->settings['maxDaysToFetchFromGitLogHistory'] . ' days');
             $logRange = '--since ' . $oldestDate->format('Y-m-d');
         }
     }
     exec('git ' . $gitDirectory . ' log ' . $logRange . ' --reverse --pretty="%H__mrX__%ai__mrX__%aE__mrX__%aN__mrX__%cE__mrX__%cN__mrX__%s"', $output);
     // check if there are new commits at all
     if (count($output) == 0) {
         $this->outputLine('-> no commits found to extract');
         return '';
     }
     // Loop over the single commits and store their data in the database
     foreach ($output as $line) {
         $lineParts = explode('__mrX__', $line);
         $this->outputLine('-> extracting commit ' . substr($lineParts[0], 0, 8));
         $commit = new \Mrimann\CoMo\Domain\Model\Commit();
         $commit->setHash($lineParts[0]);
         $date = new \DateTime($lineParts[1]);
         $commit->setDate($date);
         $commit->setAuthorEmail($lineParts[2]);
         $commit->setAuthorName($lineParts[3]);
         $commit->setCommitterEmail($lineParts[4]);
         $commit->setCommitterName($lineParts[5]);
         $commit->setCommitLine($lineParts[6]);
         $commit->setRepository($repository);
         $this->commitRepository->add($commit);
         $lastHash = $lineParts[0];
     }
     return $lastHash;
 }