From e38d9b646a65c5aa3a0b664b89cf26fbb9996aef Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 8 Oct 2013 17:19:44 +0100 Subject: [PATCH] Adding IRC plugin --- PHPCI/Builder.php | 18 ++++++++------ PHPCI/Plugin/Irc.php | 58 ++++++++++++++++++++++++++++++++++++++++++++ phpci.yml | 13 ++++++++++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 PHPCI/Plugin/Irc.php diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index e21d1dbb..0667a551 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -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(), ); } diff --git a/PHPCI/Plugin/Irc.php b/PHPCI/Plugin/Irc.php new file mode 100644 index 00000000..8658b103 --- /dev/null +++ b/PHPCI/Plugin/Irc.php @@ -0,0 +1,58 @@ + + * @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; + } +} diff --git a/phpci.yml b/phpci.yml index ce9170f0..a5ab495a 100644 --- a/phpci.yml +++ b/phpci.yml @@ -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%" \ No newline at end of file