From 5281d76416f92811d4e32be1d0fb4cbf86028d42 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 29 Aug 2017 22:10:45 +0700 Subject: [PATCH 1/2] Improved plugin composer.json and fixed PHP Censor repository URL in README.md. --- README.md | 2 +- composer.json | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cec4c61..489dc50 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a58c62e4bde1485f95b52fa56a2e4320)](https://www.codacy.com/app/LEXASOFT/PHP-Censor-Telegram-Plugin) # PHP-Censor-Telegram-Plugin -Telegram plugin for [PHP Censor](https://github.com/corpsee/php-censor) +Telegram plugin for [PHP Censor](https://github.com/php-censor/php-censor) # Installation First of all - `composer require lexasoft/php-censor-telegram-plugin` diff --git a/composer.json b/composer.json index ff48c5a..3418603 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,30 @@ { "name": "lexasoft/php-censor-telegram-plugin", "description": "PHP Censor plugin for Telegram", + "minimum-stability": "stable", + "type": "php-censor-plugin", + "keywords": [ + "php", + "php-censor", + "testing", + "open-source", + "ci", + "continuous integration", + "telegram" + ], + "homepage": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin", "license": "GPL-3.0", "authors": [ { "name": "LEXASOFT", - "email": "lexasoft83@gmail.com" + "email": "lexasoft83@gmail.com", + "role": "Developer" } ], + "support": { + "issues": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin/issues", + "source": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin" + }, "require": { "php": ">=5.3.3" }, @@ -17,7 +34,7 @@ } }, "extra": { - "phpci": { + "php-censor": { "pluginNamespace": "PHPCensor\\Plugin\\", "suppliedPlugins": [ { From c89a48e58ea7b8f3722f852afe42837c146a391f Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Tue, 29 Aug 2017 22:23:43 +0700 Subject: [PATCH 2/2] Fixed plugin for PHP Censor 0.16.0. See https://github.com/php-censor/php-censor/commit/9041457af4316c18784665875529c1dfcf8a4be9 --- composer.json | 3 ++- src/Telegram.php | 42 +++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 3418603..a595fd8 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "source": "https://github.com/LEXASOFT/PHP-Censor-Telegram-Plugin" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.3", + "guzzlehttp/guzzle": "6.2.*" }, "autoload": { "psr-4": { diff --git a/src/Telegram.php b/src/Telegram.php index cb0af27..0e5d39a 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -4,11 +4,11 @@ use PHPCensor\Builder; use PHPCensor\Model\Build; -use b8\HttpClient; +use GuzzleHttp\Client; /** * Telegram Plugin - * + * * @author LEXASOFT * @package PHPCensor * @subpackage Plugins @@ -77,28 +77,36 @@ public function execute() { $message = $this->buildMessage(); - - $http = new HttpClient('https://api.telegram.org'); - $http->setHeaders(['Content-Type: application/json']); - $uri = '/bot'. $this->apiKey . '/sendMessage'; + $client = new Client(); + $url = '/bot'. $this->apiKey . '/sendMessage'; foreach ($this->recipients as $chatId) { $params = [ - 'chat_id' => $chatId, - 'text' => $message, + 'chat_id' => $chatId, + 'text' => $message, 'parse_mode' => 'Markdown', ]; - $http->post($uri, json_encode($params)); + $client->post(('https://api.telegram.org' . $url), [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => $params, + ]); if ($this->sendLog) { $params = [ - 'chat_id' => $chatId, - 'text' => $this->buildMsg, + 'chat_id' => $chatId, + 'text' => $this->buildMsg, 'parse_mode' => 'Markdown', ]; - $http->post($uri, json_encode($params)); + $client->post(('https://api.telegram.org' . $url), [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => $params, + ]); } } @@ -112,13 +120,13 @@ public function execute() private function buildMessage() { $this->buildMsg = ''; - $buildIcon = $this->build->isSuccessful() ? '✅' : '❎'; - $buildLog = $this->build->getLog(); - $buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog); - $buildMessages = explode('RUNNING PLUGIN: ', $buildLog); + $buildIcon = $this->build->isSuccessful() ? '✅' : '❎'; + $buildLog = $this->build->getLog(); + $buildLog = str_replace(['[0;32m', '[0;31m', '[0m', '/[0m'], '', $buildLog); + $buildMessages = explode('RUNNING PLUGIN: ', $buildLog); foreach ($buildMessages as $bm) { - $pos = mb_strpos($bm, "\n"); + $pos = mb_strpos($bm, "\n"); $firstRow = mb_substr($bm, 0, $pos); //skip long outputs