From 2db88ac431000cec9c7f8f1fa4ded7689df6857d Mon Sep 17 00:00:00 2001 From: Alexandre Russo Date: Wed, 21 May 2014 11:16:05 +0200 Subject: [PATCH] =?UTF-8?q?PHPCI/Plugin/XMPP.php=20:=20Add=20new=20param?= =?UTF-8?q?=20=C2=ABdateFormat=C2=BB=20to=20display=20date/hour=20in=20not?= =?UTF-8?q?ification=20message.=20Move=20code=20to=20build=20message=20str?= =?UTF-8?q?ing=20in=20separate=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHPCI/Plugin/XMPP.php | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) 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; + } }