diff --git a/PHPCI/Plugin/XMPP.php b/PHPCI/Plugin/XMPP.php index 9bef3402..261e95a1 100644 --- a/PHPCI/Plugin/XMPP.php +++ b/PHPCI/Plugin/XMPP.php @@ -55,6 +55,11 @@ class XMPP implements \PHPCI\Plugin */ protected $recipients + /** + * @var string, mask to format date + */ + protected $dateFormat + /** * * @param Builder $phpci @@ -72,6 +77,7 @@ class XMPP implements \PHPCI\Plugin $this->alias = ''; $this->recipients= array(); $this->tls = false; + $this->dateFormat= '%d/%m/%Y %l:%M %P'; /* * Set recipients list @@ -94,7 +100,8 @@ class XMPP implements \PHPCI\Plugin */ protected function setOptions($options) { - foreach (array('username', 'password', 'alias', 'tls', 'server') as $key) { + foreach (array('username', 'password', 'alias', 'tls', 'server', 'dateFormat') + as $key) { if (array_key_exists($key, $options)) { $this->{$key} = $options[$key]; } @@ -174,24 +181,13 @@ class XMPP implements \PHPCI\Plugin $tls = ' -t'; } - /* - * Build message from status build - */ - if($this->build->isSuccessful()) { - $message = "✔ [".$this->build->getProjectTitle()."] Build #". - $this->build->getId()." successful"; - } else { - $message = "✘ [".$this->build->getProjectTitle()."] Build #". - $this->build->getId()." failure"; - } - /* * Send XMPP notification for all recipients */ $success = array() foreach($this->recipients as $recipient) { if($cmd = $this->phpci->executeCommand('echo %s | ' . $sendxmpp . - ' %s %s', $message, $tls, $recipients)) { + ' %s %s', $this->getMessage(), $tls, $recipients)) { $success[] = $cmd; } @@ -200,4 +196,25 @@ class XMPP implements \PHPCI\Plugin return (count($success) === count($this->recipients)); } + + /** + * Build message for notification + * + * @return string + */ + protected function getMessage() + { + $message = ''; + + if($this->build->isSuccessful()) { + $message = "✔ [".$this->build->getProjectTitle()."] Build #". + $this->build->getId()." successful"; + } else { + $message = "✘ [".$this->build->getProjectTitle()."] Build #". + $this->build->getId()." failure"; + } + + $message .= ' ('.strftime($this->dateFormat).')'; + return $message; + } }