Adding IRC plugin

This commit is contained in:
Dan Cryer 2013-10-08 17:19:44 +01:00
parent 357a95cb61
commit e38d9b646a
3 changed files with 82 additions and 7 deletions

View file

@ -186,13 +186,15 @@ class Builder
// Run success or failure plugins:
if ($this->success) {
$this->build->setStatus(2);
$this->executePlugins('success');
$this->logSuccess('BUILD SUCCESSFUL!');
$this->build->setStatus(2);
} else {
$this->build->setStatus(3);
$this->executePlugins('failure');
$this->logFailure('BUILD FAILED!');
$this->build->setStatus(3);
}
$this->log('');
@ -309,6 +311,7 @@ class Builder
$trans_table = array();
foreach ($this->getInterpolationVars() as $key => $value) {
$trans_table['%'.$key.'%'] = $value;
$trans_table['%PHPCI_'.$key.'%'] = $value;
}
return strtr($input, $trans_table);
}
@ -321,11 +324,12 @@ class Builder
{
$this->interpolation_vars = array(
'PHPCI' => 1,
'PHPCI_COMMIT' => $this->build->getCommitId(),
'PHPCI_PROJECT' => $this->build->getProject()->getId(),
'PHPCI_BUILD' => $this->build->getId(),
'PHPCI_PROJECT_TITLE' => $this->build->getProject()->getTitle(),
'PHPCI_BUILD_PATH' => $this->buildPath,
'COMMIT' => $this->build->getCommitId(),
'PROJECT' => $this->build->getProject()->getId(),
'BUILD' => $this->build->getId(),
'PROJECT_TITLE' => $this->build->getProject()->getTitle(),
'BUILD_PATH' => $this->buildPath,
'BUILD_URI' => PHPCI_URL . "build/view/" . $this->build->getId(),
);
}

58
PHPCI/Plugin/Irc.php Normal file
View file

@ -0,0 +1,58 @@
<?php
namespace PHPCI\Plugin;
/**
* IRC Plugin - Sends a notification to an IRC channel
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class Irc implements \PHPCI\Plugin
{
private $phpci;
private $message;
private $server;
private $port;
private $room;
private $nick;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->message = $options['message'];
$buildSettings = $phpci->getConfig('build_settings');
if (isset($buildSettings['irc'])) {
$irc = $buildSettings['irc'];
$this->server = $irc['server'];
$this->port = $irc['port'];
$this->room = $irc['room'];
$this->nick = $irc['nick'];
}
}
public function execute()
{
$msg = $this->phpci->interpolate($this->message);
if (empty($this->server) || empty($this->room) || empty($this->nick)) {
$this->phpci->logFailure('You must configure a server, room and nick.');
}
if (empty($this->port)) {
$this->port = 6667;
}
$sock = fsockopen($this->server, $this->port);
fputs($sock, 'USER ' . $this->nick . ' phptesting.org ' . $this->nick . ' :' . $this->nick . "\r\n");
fputs($sock, 'NICK ' . $this->nick . "\r\n");
fputs($sock, 'PRIVMSG ' . $this->room . ' :' . $msg . "\r\n");
fclose($sock);
return true;
}
}

View file

@ -6,6 +6,11 @@ build_settings:
- "build"
- "Tests"
- "composer.phar"
irc:
server: "irc.freenode.net"
port: 6667
room: "#phpci"
nick: "phpcidev"
setup:
composer:
@ -18,3 +23,11 @@ test:
standard: "PSR2"
php_loc:
allow_failures: true
success:
irc:
message: "Build Success! %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%"
failure:
irc:
message: "Build Failed :( %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%"