PHPCI/Plugin/XMPP.php : Add new param «dateFormat» to display date/hour in notification message. Move code to build message string in separate method
This commit is contained in:
parent
7f05051dc7
commit
40b52fb1bd
1 changed files with 30 additions and 13 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue