Пример #1
0
 /**
  * Computes the number of revisions commited by each user
  *
  * @param int $startRevision First revision to work on
  * @param int $endRevision   Last revision to work on
  * @return array Computed data
  */
 protected function _computeRevisionsCountByAuthor($startRevision, $endRevision)
 {
     VcsStats_Runner_Cli::displayMessage('Calculating revisions count by author');
     $table = new VcsStats_Report_Element_Table();
     $table->setCode('revisions_count_by_author');
     $table->setTitle('Revisions count by author');
     $table->addColumn(new VcsStats_Report_Element_Table_Column('Author', 'author'));
     $table->addColumn(new VcsStats_Report_Element_Table_Column('Count', 'count', VcsStats_Report_Element_Table_Column::ALIGNMENT_RIGHT));
     $where = '';
     if (null !== $startRevision && null != $endRevision) {
         $where = "WHERE id >= {$startRevision} AND id <= {$endRevision}";
     }
     $sql = "SELECT author, COUNT(*) AS count\n                FROM revisions\n                {$where}\n                GROUP BY author\n                ORDER BY count DESC";
     $data = $this->_cache->fetchAll($sql);
     $table->setRows($data);
     return $table;
 }
Пример #2
0
 /**
  * Main function. Sets up the environment and coordinate the work.
  *
  * @return void
  */
 public static function run()
 {
     // Set autoload up
     require_once 'VcsStats/Loader.php';
     spl_autoload_register(array('VcsStats_Loader', 'autoload'));
     require_once 'ezc/Base/base.php';
     spl_autoload_register(array('ezcBase', 'autoload'));
     // Set console output up
     $output = new ezcConsoleOutput();
     $output->formats->version->style = array('bold');
     $output->formats->debug->color = 'yellow';
     $output->formats->debug->style = array('italic');
     $output->formats->error->color = 'red';
     self::$consoleOutput = $output;
     // Set console input up
     $input = new ezcConsoleInput();
     self::$consoleInput = $input;
     $debugOption = new ezcConsoleOption('d', 'debug');
     $debugOption->type = ezcConsoleInput::TYPE_NONE;
     $input->registerOption($debugOption);
     $helpOption = new ezcConsoleOption('h', 'help');
     $helpOption->type = ezcConsoleInput::TYPE_NONE;
     $input->registerOption($helpOption);
     $revisionsOption = new ezcConsoleOption('r', 'revisions');
     $revisionsOption->type = ezcConsoleInput::TYPE_STRING;
     $input->registerOption($revisionsOption);
     $verboseOption = new ezcConsoleOption('v', 'verbose');
     $verboseOption->type = ezcConsoleInput::TYPE_NONE;
     $input->registerOption($verboseOption);
     $versionOption = new ezcConsoleOption(null, 'version');
     $versionOption->type = ezcConsoleInput::TYPE_NONE;
     $input->registerOption($versionOption);
     // Process console input
     try {
         $input->process();
     } catch (ezcConsoleOptionException $exception) {
         echo $exception->getMessage() . "\n";
         exit(1);
     }
     if ($input->getOption('help')->value) {
         self::displayHelp();
         exit(0);
     } else {
         if ($input->getOption('version')->value) {
             self::displayVersion();
             exit(0);
         }
     }
     $arguments = $input->getArguments();
     if (1 !== count($arguments)) {
         self::displayError('Path to repository is missing', 'error');
         exit(1);
     }
     $repositoryPath = $arguments[0];
     // Do the actual work
     self::displayVersion();
     try {
         $options = array('path' => $repositoryPath);
         $wrapper = new VcsStats_Wrapper_Subversion($options);
         $cachePath = realpath(dirname(__FILE__) . '/../../tmp');
         $cache = new VcsStats_Cache($wrapper, $cachePath);
         $revisionsRange = self::_extractRevisionsRange($input->getOption('revisions')->value);
         $cache->updateData($revisionsRange['end']);
         $analyzer = new VcsStats_Analyzer($cache);
         $report = $analyzer->getReport($revisionsRange['start'], $revisionsRange['end']);
         $renderer = new VcsStats_Renderer_Text();
         $renderer->render($report);
     } catch (Exception $exception) {
         self::displayError($exception->getMessage());
         exit(1);
     }
 }