/** * (non-PHPdoc) * @see Symfony\Component\Console\Command.Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { // Load configuration file $configPath = $input->getOption('config'); if (null === $configPath) { $configPath = $this->getDefaultConfigPath(); } try { $config = $this->loadConfig($configPath); } catch (Exception $exception) { $output->writeln($exception->getMessage()); exit(1); } // Let's assume configuration file is at the root of the project local repository // TODO: Allow to set path to the repository in the configuration file $projectPath = dirname($configPath); // The only VCS supported is Git for now so there is no choice // TODO: Support more VCS $vcs = new GitDriver($projectPath); $commit = $vcs->getCommit($input->getArgument('hash')); // Build commit $builder = new Builder($config); $report = $builder->buildCommit($commit); // Prepare event to be broadcasted $event = new Event(); $title = $report->isSuccessfull() ? 'Build succeed' : 'Build failed'; $event->setTitle($title); // Broadcast report // TODO: Allow to define notifiers in the configuration file $notifier = new GrowlNotifier(); $notifier->handleEvent($event); }
protected function notify(Event $event) { $request = 'GNTP/1.0 NOTIFY NONE' . self::EOL; $request .= 'Application-Name: ' . $this->getApplicationName() . self::EOL; $request .= 'Notification-Name: Notify' . self::EOL; $request .= 'Notification-Title: ' . $event->getTitle() . self::EOL; $request .= 'Notification-Text: ' . $event->getMessage() . self::EOL; $request .= self::EOL . self::EOL; return $this->sendRequest($request); }
public function handle(Event $event) { $timestamp = $event->getTimestamp(); if (empty($timestamp)) { $event->setTimestamp(time()); } foreach ($this->notifiers as $notifier) { $notifier->handleEvent($event); } }
public function format(Event $event) { $format = $this->getFormat(); // Process timestamp preg_match('/%timestamp:(.*?)%/', $format, $matches); list($timestampTag, $timestampFormat) = $matches; $timestamp = date($timestampFormat, $event->getTimestamp()); $format = str_replace($timestampTag, $timestamp, $format); // Process the other items $extras = array(); foreach ($event->getExtras() as $name => $value) { $extras[] = $name . ': ' . $value; } $data = array('%extras%' => implode(', ', $extras), '%message%' => $event->getMessage(), '%picture%' => $event->getPicture(), '%title%' => $event->getTitle(), '%type%' => $event->getType()); return strtr($format . $this->getEol(), $data); }
public function format(Event $event) { $encoding = $this->getEncoding(); $dom = new \DOMDocument('1.0', $encoding); $rootNode = $dom->appendChild(new \DOMElement('event')); $data = array('type' => $event->getType(), 'timestamp' => $event->getTimestamp(), 'title' => $event->getTitle(), 'message' => $event->getMessage(), 'picture' => $event->getPicture()); foreach ($data as $name => $value) { $this->appendNode($rootNode, $name, $value); } $extrasNode = $rootNode->appendChild(new \DOMElement('extras')); foreach ($event->getExtras() as $name => $value) { $this->appendNode($extrasNode, $name, $value); } $xml = $dom->saveXML(); // Remove XML protocol $xml = preg_replace('/<\\?xml version="1.0"( encoding="[^\\"]*")?\\?>\\n/u', '', $xml); return $xml; }
public function format(Event $event) { $data = array('type' => $event->getType(), 'timestamp' => $event->getTimestamp(), 'title' => $event->getTitle(), 'message' => $event->getMessage(), 'picture' => $event->getPicture(), 'extras' => $event->getExtras()); return json_encode($data); }