예제 #1
0
 /**
  * Index action
  *
  * @return void
  */
 public function indexAction()
 {
     $monthIdentifier = $this->electomatService->getMonthIdentifierLastMonth();
     $this->view->assign('numberOfCommits', $this->commitRepository->getCommitsByMonth($monthIdentifier)->count());
     $this->view->assign('numberOfActiveRepositories', $this->repositoryRepository->extractTheRepositoriesFromAStackOfCommits($this->commitRepository->getCommitsByMonth($monthIdentifier))->count());
     $this->view->assign('numberOfMonitoredRepositories', $this->repositoryRepository->countByIsActive(TRUE));
     $this->view->assign('numberOfCommitters', $this->aggregatedDataPerUserRepository->findNumberOfCommittersPerMonth($monthIdentifier));
     $this->view->assign('coderOfTheMonthAward', $this->awardRepository->findLatestAwards(1)->getFirst());
     $this->view->assign('currentTopicAwards', $this->awardRepository->findCurrentTopicAwards());
 }
 /**
  * Processes the cached meta data and aggregates it to a usable format so they can be used easily
  * for showing some results.
  *
  * @param boolean whether the script should avoid any output
  * @return void
  */
 public function processCommitsCommand($quiet = FALSE)
 {
     $this->quiet = $quiet;
     $unprocessedCommits = $this->commitRepository->findByIsAggregated(FALSE);
     if ($unprocessedCommits->count() == 0) {
         $this->outputLine('There are no commits to be processed.');
         return;
     }
     $numberOfProcessedCommits = 0;
     foreach ($unprocessedCommits as $commit) {
         $this->processSingleCommit($commit);
         $commit->setIsAggregated(TRUE);
         $this->commitRepository->update($commit);
         $this->persistenceManager->persistAll();
         $numberOfProcessedCommits++;
     }
     $this->outputLine('-> aggregated ' . $numberOfProcessedCommits . ' commits.');
 }
 /**
  * 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;
 }