Exemplo n.º 1
0
 /**
  * Executes the current command.
  *
  * @param  InputInterface $input An InputInterface instance
  * @param  OutputInterface $output An OutputInterface instance
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $oConfig = new \Testy\Config($input->getOption('config'));
         $oConfig->validate();
         $bFirstRun = true;
         $oWatch = new \Testy\Watch();
         while (true) {
             $oRawConfig = $oConfig->get();
             if ($bFirstRun === true or $oConfig->wasUpdated() === true) {
                 $aNotifiers = array();
                 foreach ($oRawConfig->setup->notifiers as $sNotifier => $oNotifierConfig) {
                     if (isset($oNotifierConfig->enabled) === true and $oNotifierConfig->enabled == true) {
                         $aNotifiers[$sNotifier] = \notifyy\Builder::build($sNotifier, $oNotifierConfig);
                     }
                 }
                 foreach ($oRawConfig->projects as $sProject => $oProjectConfig) {
                     $oWatch->add(\Testy\Project\Builder::build($sProject, $oProjectConfig, $aNotifiers));
                 }
             }
             $oWatch->loop($oRawConfig->setup->parallel, $oRawConfig->setup->sleep);
             sleep($oRawConfig->setup->sleep);
             $bFirstRun = false;
         }
     } catch (\Testy\Exception $e) {
         $output->writeln($e->getMessage());
         return 1;
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Handle passed arguments
  *
  * @param array $argv
  *
  * @return Command
  *
  * @TODO Cleanup!
  */
 public function handleArguments(array $argv = array())
 {
     try {
         $this->_aArguments = \Mergy\TextUI\Parameter::parse($argv, $this);
     } catch (\Mergy\TextUI\Parameter\Exception $oException) {
         return false;
     }
     if (defined('VERBOSE') === false) {
         define('VERBOSE', $this->_aArguments['verbose']);
     }
     $sConfig = self::CONFIG_FILE;
     if (isset($this->_aArguments['config']) === true) {
         $sConfig = $this->_aArguments['config'];
     }
     if (file_exists($sConfig) === true) {
         $this->_aArguments['config'] = json_decode(file_get_contents($sConfig));
     }
     if (empty($this->_aArguments['config']) === true) {
         \Mergy\TextUI\Output::error(self::CONFIG_ERROR);
         return false;
     }
     if ($this->_aArguments['config'] instanceof \stdClass !== true) {
         $this->_aArguments['config'] = new \stdClass();
     }
     if (empty($this->_aArguments['remote']) !== true and preg_match('!http(s)?://!i', $this->_aArguments['remote']) === 0) {
         if (isset($this->_aArguments['config']->remote) === true) {
             $aRemote = explode('/', $this->_aArguments['config']->remote);
             $aRemote[count($aRemote) - 1] = $this->_aArguments['remote'];
             $this->_aArguments['remote'] = implode('/', $aRemote);
         }
     }
     foreach ($this->_aConfig as $sArg => $sConfig) {
         if (empty($this->_aArguments[$sArg]) !== true) {
             $this->_aArguments['config']->{$sConfig} = $this->_aArguments[$sArg];
             unset($this->_aArguments[$sArg]);
         } elseif (isset($this->_aArguments['config']->{$sConfig}) === false) {
             $this->_aArguments['config']->{$sConfig} = null;
         }
     }
     $this->_aArguments['config']->tickets = explode(',', $this->_aArguments['config']->tickets);
     $this->_aArguments['config']->force = explode(',', $this->_aArguments['config']->force);
     if ($this->_aArguments['strict'] === true) {
         $this->_aArguments['config']->force = false;
     }
     if (empty($this->_aArguments['config']->notifiers) === true) {
         $this->_aArguments['config']->notifiers = null;
     }
     if (empty($this->_aArguments['config']->parallel) === true) {
         $this->_aArguments['config']->parallel = null;
     }
     if (empty($this->_aArguments['config']->merge) === true) {
         $this->_aArguments['config']->merge = array('ticket', 'comment', 'revision');
     }
     try {
         $this->_oNotifier = \notifyy\Builder::build($this->_aArguments['config']->notifiers);
     } catch (\notifyy\Exception $oNotifyyException) {
         \Mergy\TextUI\Output::error($oNotifyyException->getMessage());
         return false;
     }
     if (defined('VERBOSE') === true and VERBOSE === true) {
         \Mergy\TextUI\Output::info(print_r($this->_aArguments, true));
     }
     $this->_oMergeTracker = new \Mergy\Util\Merge\Tracker($this->_aArguments['config']);
     $oAction = new \Mergy\Action($this->_aArguments['config'], $this->_oNotifier);
     if ($this->_aArguments['config']->continue !== true) {
         $oAction->setup()->init();
         $this->_oMergeTracker->clean();
     }
     try {
         $this->_aArguments = \Mergy\TextUI\Parameter::revisions($this->_aArguments, $oAction->command('Unmerged'));
     } catch (\Exception $oException) {
         \Mergy\TextUI\Output::error($oException->getMessage());
         return false;
     }
     $aTrackedTickets = $this->_oMergeTracker->get();
     sort($aTrackedTickets);
     $this->_aArguments['config']->tracked = $aTrackedTickets;
     unset($oAction);
     return $this;
 }