diff --git a/etc/default.tasks.properties b/etc/default.tasks.properties index d027f06b8..1e536b8cd 100644 --- a/etc/default.tasks.properties +++ b/etc/default.tasks.properties @@ -102,7 +102,6 @@ growlnotify=Phing\Task\Ext\GrowlNotifyTask wikipublish=Phing\Task\Ext\WikiPublishTask stopwatch=Phing\Task\Ext\StopwatchTask symfonyconsole=Phing\Task\Ext\SymfonyConsoleTask -hipchat=Phing\Task\Ext\HipchatTask open=Phing\Task\Ext\OpenTask inifile=Phing\Task\Ext\IniFile\IniFileTask diff --git a/src/Phing/Task/Ext/HipchatTask.php b/src/Phing/Task/Ext/HipchatTask.php deleted file mode 100644 index 536a2ab87..000000000 --- a/src/Phing/Task/Ext/HipchatTask.php +++ /dev/null @@ -1,218 +0,0 @@ -. - */ - -namespace Phing\Task\Ext; - -use Phing\Exception\BuildException; -use Phing\Project; -use Phing\Task; - -/** - * HipchatTask - * Sends a simple hipchat notification. - * - * (Yeah, HipChat API has lots of more awesome features than sending a lousy text notification - * but I refuse implementing more as long as the chat client lacks the most basic feature of - * sorting contacts. If you share my opinion then please upvote this feature request: - * https://jira.atlassian.com/browse/HCPUB-363 ) - * - * - * Hello <i>World</i>! - * - * - * @author Suat Özgür - */ -class HipchatTask extends Task -{ - private $domain = 'api.hipchat.com'; - private $room; - private $authToken; - private $color = 'yellow'; - private $notify = false; - private $message; - private $format = 'text'; - - public function main() - { - if (null === $this->getRoom()) { - throw new BuildException('(HipChat) room is not defined'); - } - - if (null === $this->getAuthToken()) { - throw new BuildException('(HipChat) authToken is not defined'); - } - - $url = - 'https://' . - $this->getDomain() . - '/v2/room/' . - $this->getRoom() . - '/notification?auth_token=' . - $this->getAuthToken(); - - $data = [ - 'color' => $this->getColor(), - 'message' => $this->getMessage(), - 'notify' => $this->isNotify(), - 'message_format' => $this->getFormat(), - ]; - - $result = $this->executeApiCall($url, $data); - if (true !== $result) { - $this->log($result, Project::MSG_WARN); - } else { - $this->log('HipChat notification sent.'); - } - } - - /** - * @return string - */ - public function getDomain() - { - return $this->domain; - } - - /** - * @param string $domain - */ - public function setDomain($domain) - { - $this->domain = $domain; - } - - /** - * @return string - */ - public function getFormat() - { - return $this->format; - } - - /** - * @param $format - */ - public function setFormat($format) - { - $format = ('text' != $format && 'html' != $format) ? 'text' : $format; - $this->format = $format; - } - - /** - * @return string - */ - public function getRoom() - { - return $this->room; - } - - /** - * @param string $room - */ - public function setRoom($room) - { - $this->room = $room; - } - - /** - * @return string - */ - public function getAuthToken() - { - return $this->authToken; - } - - /** - * @param string $authToken - */ - public function setAuthToken($authToken) - { - $this->authToken = $authToken; - } - - /** - * @return string - */ - public function getColor() - { - return $this->color; - } - - /** - * @param string $color - */ - public function setColor($color) - { - $this->color = $color; - } - - /** - * @return string - */ - public function getMessage() - { - return $this->message; - } - - /** - * @return bool - */ - public function isNotify() - { - return $this->notify; - } - - /** - * @param bool $notify - */ - public function setNotify($notify) - { - $this->notify = $notify; - } - - /** - * @param $message - */ - public function addText($message) - { - $this->message = trim($message); - } - - private function executeApiCall($url, $data) - { - $postData = json_encode($data); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); - curl_setopt($ch, CURLOPT_POST, 1); - $response = curl_exec($ch); - if ('' !== $response) { - $result = json_decode($response, 1); - - return $result['error']['message'] . ' (' . $result['error']['code'] . ')'; - } - - return true; - } -}