From f311371d6b9e70b333cb95589a4afb5700d4ba30 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 20 Apr 2024 09:01:12 +0000 Subject: [PATCH 01/16] Fix YAML examples (#169) Fix formatting of example feeds YAML. Closes https://github.com/VerifiedJoseph/vigilant/issues/168 --- docs/feeds.md | 15 +++++++-------- feeds.example.yaml | 7 +++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/feeds.md b/docs/feeds.md index 719c271b..dff22134 100644 --- a/docs/feeds.md +++ b/docs/feeds.md @@ -10,14 +10,13 @@ Each entry in the YAML file must have a name, URL and interval parameter. All ot ```YAML feeds: - - - name: Met Office weather warnings - url: http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/UK - interval: 1900 - - - name: GitHub Status - url: https://www.githubstatus.com/history.rss - interval: 600 + - name: Met Office weather warnings + url: http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/UK + interval: 1900 + + - name: GitHub Status + url: https://www.githubstatus.com/history.rss + interval: 600 ``` | Name | Required | Description | diff --git a/feeds.example.yaml b/feeds.example.yaml index 6f2353f8..d4e8f4f6 100644 --- a/feeds.example.yaml +++ b/feeds.example.yaml @@ -1,5 +1,4 @@ feeds: - - - name: Met Office weather warnings - url: http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/UK - interval: 900 + - name: Met Office weather warnings + url: http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/UK + interval: 1900 From 7ac91e8665217f015ca425adf437e0b8542c4504 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 Apr 2024 09:04:42 +0000 Subject: [PATCH 02/16] Bump php from 8.2.17-cli-alpine3.19 to 8.2.18-cli-alpine3.19 in /.devcontainer/workspace (#170) --- .devcontainer/workspace/dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/workspace/dockerfile b/.devcontainer/workspace/dockerfile index 3271033b..37080a1c 100644 --- a/.devcontainer/workspace/dockerfile +++ b/.devcontainer/workspace/dockerfile @@ -1,5 +1,5 @@ FROM composer:2.7.2 AS composer -FROM php:8.2.17-cli-alpine3.19 +FROM php:8.2.18-cli-alpine3.19 RUN apk add --update --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \ && pecl install xdebug \ From 51db7be796ef6fdb04b2ead6004dcc91a6ddc251 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sat, 20 Apr 2024 10:25:16 +0000 Subject: [PATCH 03/16] Add bug report issue template (#171) --- .github/ISSUE_TEMPLATE/bug_report.yml | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000..6667fb90 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,43 @@ +name: Bug report +description: Report a bug +labels: + - bug +body: + - type: textarea + attributes: + label: Describe the bug + description: Provide a concise description of what the bug is. + validations: + required: true + - type: textarea + attributes: + label: Configuration + description: >- + Provide a complete `docker-compose` and\or `config.php` + configuration file. + - type: input + attributes: + label: Version + description: What version of Vigilant can you reproduce this bug on? + validations: + required: true + - type: dropdown + attributes: + label: ' Deployment Method' + description: How have you deployed vigilant? + options: + - Docker compose + - Manually + - Other + validations: + required: true + - type: input + attributes: + label: PHP Version + description: What version of php are you using to run Vigilant? + validations: + required: false + - type: textarea + attributes: + label: Additional context + description: Add any other context about the problem here. From b696629bc82d791c55813367621a88436a2d99e8 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 29 Apr 2024 12:21:00 +0000 Subject: [PATCH 04/16] Add `Logger` class (#172) --- daemon.php | 13 +-- src/Check.php | 42 ++++++---- src/Feeds.php | 18 +++-- src/Logger.php | 99 +++++++++++++++++++++++ src/Notification/AbstractNotification.php | 14 +++- src/Notification/Gotify.php | 3 +- src/Notification/Ntfy.php | 2 +- src/Notify.php | 54 +++++++------ src/Output.php | 8 -- tests/CheckTest.php | 16 ++-- tests/FeedsTest.php | 19 +++-- tests/LoggerTest.php | 74 +++++++++++++++++ tests/Notification/GotifyTest.php | 15 +++- tests/Notification/NtfyTest.php | 19 +++-- tests/NotifyTest.php | 31 ++++--- tests/OutputTest.php | 10 --- vigilant.php | 26 +++--- 17 files changed, 345 insertions(+), 118 deletions(-) create mode 100644 src/Logger.php create mode 100644 tests/LoggerTest.php diff --git a/daemon.php b/daemon.php index c8a0b50d..926addcc 100644 --- a/daemon.php +++ b/daemon.php @@ -6,6 +6,7 @@ use Vigilant\Fetch; use Vigilant\Notify; use Vigilant\Output; +use Vigilant\Logger; use Vigilant\Version; use Vigilant\Exception\ConfigException; use Vigilant\Exception\AppException; @@ -19,23 +20,25 @@ $config->validate(); $fetch = new Fetch(); - $feeds = new Feeds($config); + $logger = new Logger($config->getTimezone()); + $feeds = new Feeds($config, $logger); /** @phpstan-ignore-next-line */ while (true) { foreach ($feeds->get() as $details) { - $notify = new Notify($details, $config); + $notify = new Notify($details, $config, $logger); $check = new Check( $details, + $fetch, $config, - $fetch + $logger ); if ($check->isDue() === true) { $check->check(); $notify->send($check->getMessages()); - Output::text(sprintf( + $logger->info(sprintf( 'Next check in %s seconds at %s', $details->getInterval(), $check->getNextCheckDate() @@ -46,6 +49,6 @@ sleep(30); } } catch (ConfigException | AppException $err) { - Output::text($err->getMessage()); + Output::text('[Vigilant] ' . $err->getMessage()); exit(1); } diff --git a/src/Check.php b/src/Check.php index 08fb642e..0752b4b8 100644 --- a/src/Check.php +++ b/src/Check.php @@ -9,14 +9,17 @@ final class Check { - /** @var Config */ - private Config $config; + /** @var Feed\Details $details Feed details (name, url, interval and hash) */ + private Feed\Details $details; - /** @var Fetch */ + /** @var Fetch Fetch class instance */ private Fetch $fetch; - /** @var Feed\Details $details Feed details (name, url, interval and hash) */ - private Feed\Details $details; + /** @var Config Config class instance */ + private Config $config; + + /** @var Logger Logger class instance */ + private Logger $logger; /** @var Cache $cache Cache class instance */ private Cache $cache; @@ -29,14 +32,16 @@ final class Check /** * @param Feed\Details $details Feed details - * @param Config $config Script config + * @param Config $config Config class instance * @param Fetch $fetch Fetch class instance + * @param Logger $logger Logger class instance */ - public function __construct(Feed\Details $details, Config $config, Fetch $fetch) + public function __construct(Feed\Details $details, Fetch $fetch, Config $config, Logger $logger) { $this->details = $details; - $this->config = $config; $this->fetch = $fetch; + $this->config = $config; + $this->logger = $logger; $this->cache = new Cache( $this->config->getCachePath(), @@ -78,14 +83,18 @@ public function getNextCheckDate(): string public function check(): void { try { - Output::text('Checking...' . $this->details->getName() . ' (' . $this->details->getUrl() . ')'); + $this->logger->info(sprintf( + 'Checking...%s (%s)', + $this->details->getName(), + $this->details->getUrl() + )); $result = $this->fetch->get($this->details->getUrl()); $this->process($result); $this->cache->resetErrorCount(); } catch (FetchException $err) { - Output::text($err->getMessage()); + $this->logger->error($err->getMessage()); $this->cache->increaseErrorCount(); @@ -129,24 +138,27 @@ private function process(\FeedIo\Reader\Result $result): void if (in_array($hash, $this->cache->getItems()) === false) { $newItems += 1; - Output::text('Found...' . html_entity_decode($item->getTitle()) . ' (' . $hash . ')'); + $title = html_entity_decode($item->getTitle()); + $body = strip_tags(html_entity_decode($item->getContent())); + + $this->logger->info(sprintf('Found...%s (%s)', $title, $hash)); if ($this->cache->isFirstCheck() === false) { $this->messages[] = new Message( - title: html_entity_decode($item->getTitle()), - body: strip_tags(html_entity_decode($item->getContent())), + title: $title, + body: $body, url: $item->getLink() ); } } } - Output::text('Found ' . $newItems . ' new item(s).'); + $this->logger->info(sprintf('Found %s new item(s).', $newItems)); $this->cache->updateItems($itemHashes); if ($newItems > 0 && $this->cache->isFirstCheck() === true) { - Output::text('First feed check, not sending notifications for found items.'); + $this->logger->info('First feed check, not sending notifications for found items.'); } } } diff --git a/src/Feeds.php b/src/Feeds.php index 4fbba40e..15a8a0ad 100644 --- a/src/Feeds.php +++ b/src/Feeds.php @@ -2,7 +2,6 @@ namespace Vigilant; -use Vigilant\Check; use Vigilant\Feed\Feed; use Vigilant\Feed\Details; use Vigilant\Exception\AppException; @@ -17,19 +16,24 @@ final class Feeds */ private Config $config; + /** + * @var Logger + */ + private Logger $logger; + /** * @var array $feeds Feed classes for each feeds.yaml entry */ private array $feeds = []; /** - * Constructor - * - * @param Config $config Feeds filepath + * @param Config $config Config class instance + * @param Logger $logger Logger class instance */ - public function __construct(Config $config) + public function __construct(Config $config, Logger $logger) { $this->config = $config; + $this->logger = $logger; try { $feeds = $this->load($this->config->getFeedsPath()); @@ -60,7 +64,7 @@ public function get(): array private function load(string $path): array { try { - Output::text('Loading feeds.yaml (' . $path . ')'); + $this->logger->debug(sprintf('Loading feeds.yaml (%s)', $path)); return Yaml::parseFile($path); } catch (ParseException $err) { @@ -76,7 +80,7 @@ private function load(string $path): array */ private function validate(array $feeds): void { - Output::text('Validating feeds.yaml'); + $this->logger->debug('Validating feeds.yaml'); if (array_key_exists('feeds', $feeds) === false || is_array($feeds['feeds']) === false) { throw new FeedsException('No feeds in feeds.yaml'); diff --git a/src/Logger.php b/src/Logger.php new file mode 100644 index 00000000..5da2a3e7 --- /dev/null +++ b/src/Logger.php @@ -0,0 +1,99 @@ +setLevel($level); + $this->timezone = new DateTimeZone($timezone); + } + + /** + * Display text in terminal + * + * @param string $text Text string to display + */ + public function info(string $text): void + { + $this->log($text); + } + + /** + * Display error text in terminal + * + * @param string $text Text string to display + */ + public function error(string $text): void + { + $this->log($text); + } + + /** + * Display text in terminal when debugging is enabled + * + * @param string $text Text string to display + */ + public function debug(string $text): void + { + if ($this->logLevel === 2) { + $this->log($text); + } + } + + /** + * Display text in terminal + * + * @param string $text Text string to display + */ + private function log(string $text): void + { + $date = new DateTime('now', $this->timezone); + + echo sprintf( + '[%s] %s %s', + $date->format('Y-m-d h:i:s P'), + $text, + PHP_EOL + ); + } + + /** + * Set logging level + * + * - `1` - Normal + * - `2` - Verbose + * + * @param int $level Logging level + */ + private function setLevel(int $level): void + { + if ($level < 1) { + $this->logLevel = 1; + } elseif ($level > 2) { + $this->logLevel = 2; + } else { + $this->logLevel = $level; + } + } +} diff --git a/src/Notification/AbstractNotification.php b/src/Notification/AbstractNotification.php index a3674abe..03c1a0ff 100644 --- a/src/Notification/AbstractNotification.php +++ b/src/Notification/AbstractNotification.php @@ -2,19 +2,25 @@ namespace Vigilant\Notification; +use Vigilant\Logger; + abstract class AbstractNotification { - /** - * @var array $config Notification config - */ + /** @var array $config Notification config */ protected array $config = []; + /** @var Logger Logger class instance */ + protected Logger $logger; + /** * @param array $config Notification config + * @param Logger $logger Logger class instance */ - public function __construct(array $config) + public function __construct(array $config, Logger $logger) { $this->config = $config; + $this->logger = $logger; + $this->setup(); } diff --git a/src/Notification/Gotify.php b/src/Notification/Gotify.php index ac0eb049..289583e6 100644 --- a/src/Notification/Gotify.php +++ b/src/Notification/Gotify.php @@ -2,7 +2,6 @@ namespace Vigilant\Notification; -use Vigilant\Output; use Vigilant\Notification\AbstractNotification; use Vigilant\Exception\NotificationException; use Gotify\Server; @@ -35,7 +34,7 @@ public function send(string $title, string $body, string $url = ''): void ] ); - Output::text('Sent notification using Gotify'); + $this->logger->info('Sent notification using Gotify'); } catch (EndpointException | GotifyException $err) { throw new NotificationException('[Gotify] ' . $err->getMessage()); } diff --git a/src/Notification/Ntfy.php b/src/Notification/Ntfy.php index c44c8ada..faa588e2 100644 --- a/src/Notification/Ntfy.php +++ b/src/Notification/Ntfy.php @@ -37,7 +37,7 @@ public function send(string $title, string $body, string $url = ''): void $this->client->send($message); - Output::text('Sent notification using Ntfy'); + $this->logger->info('Sent notification using Ntfy'); } catch (EndpointException | NtfyException $err) { throw new NotificationException('[Ntfy] ' . $err->getMessage()); } diff --git a/src/Notify.php b/src/Notify.php index bc7224fc..d9514806 100644 --- a/src/Notify.php +++ b/src/Notify.php @@ -11,18 +11,28 @@ class Notify { private AbstractNotification $service; + /** @var Config Config class instance */ + private Config $config; + + /** @var Logger Logger class instance */ + private Logger $logger; + /** * Create and config Notification class * * @param Feed\Details $details Feed details - * @param Config $config Script config + * @param Config $config Config class instance + * @param Logger $logger Logger class instance */ - public function __construct(Feed\Details $details, Config $config) + public function __construct(Feed\Details $details, Config $config, Logger $logger) { + $this->config = $config; + $this->logger = $logger; + if ($config->getNotificationService() === 'gotify') { - $this->service = $this->createGotify($details, $config); + $this->service = $this->createGotify($details); } else { - $this->service = $this->createNtfy($details, $config); + $this->service = $this->createNtfy($details); } } @@ -40,7 +50,7 @@ public function send(array $messages): void $message->getUrl() ); } catch (NotificationException $err) { - Output::text($err->getMessage()); + $this->logger->error($err->getMessage()); } } } @@ -49,14 +59,13 @@ public function send(array $messages): void * Create and config Gotify instance * * @param Feed\Details $details Feed details - * @param Config $config Script config */ - private function createGotify(Feed\Details $details, Config $config): Gotify + private function createGotify(Feed\Details $details): Gotify { $gotifyConfig = [ - 'server' => $config->getGotifyUrl(), - 'priority' => $config->getGotifyPriority(), - 'token' => $config->getGotifyToken() + 'server' => $this->config->getGotifyUrl(), + 'priority' => $this->config->getGotifyPriority(), + 'token' => $this->config->getGotifyToken() ]; if ($details->hasGotifyPriority() === true) { @@ -67,31 +76,30 @@ private function createGotify(Feed\Details $details, Config $config): Gotify $gotifyConfig['token'] = $details->getGotifyToken(); } - return new Gotify($gotifyConfig); + return new Gotify($gotifyConfig, $this->logger); } /** * Create and config ntfy instance * * @param Feed\Details $details Feed details - * @param Config $config Script config */ - private function createNtfy(Feed\Details $details, Config $config): Ntfy + private function createNtfy(Feed\Details $details): Ntfy { $ntfyConfig = [ - 'server' => $config->getNtfyUrl(), - 'topic' => $config->getNtfyTopic(), - 'priority' => $config->getNtfyPriority(), + 'server' => $this->config->getNtfyUrl(), + 'topic' => $this->config->getNtfyTopic(), + 'priority' => $this->config->getNtfyPriority(), 'auth' => [ - 'method' => $config->getNtfyAuthMethod() + 'method' => $this->config->getNtfyAuthMethod() ] ]; - if ($config->getNtfyAuthMethod() === 'password') { - $ntfyConfig['auth']['username'] = $config->getNtfyUsername(); - $ntfyConfig['auth']['password'] = $config->getNtfyPassword(); - } elseif ($config->getNtfyAuthMethod() === 'token') { - $ntfyConfig['auth']['token'] = $config->getNtfyToken(); + if ($this->config->getNtfyAuthMethod() === 'password') { + $ntfyConfig['auth']['username'] = $this->config->getNtfyUsername(); + $ntfyConfig['auth']['password'] = $this->config->getNtfyPassword(); + } elseif ($this->config->getNtfyAuthMethod() === 'token') { + $ntfyConfig['auth']['token'] = $this->config->getNtfyToken(); } if ($details->hasNtfyToken() === true) { @@ -109,6 +117,6 @@ private function createNtfy(Feed\Details $details, Config $config): Ntfy $ntfyConfig['priority'] = $details->getNtfyPriority(); } - return new Ntfy($ntfyConfig); + return new Ntfy($ntfyConfig, $this->logger); } } diff --git a/src/Output.php b/src/Output.php index e7545565..58d51762 100644 --- a/src/Output.php +++ b/src/Output.php @@ -13,12 +13,4 @@ public static function text(string $text = ''): void { echo $text . "\n"; } - - /** - * Output system newline character in terminal - */ - public static function newline(): void - { - echo PHP_EOL; - } } diff --git a/tests/CheckTest.php b/tests/CheckTest.php index 41a3052c..e043d0dc 100644 --- a/tests/CheckTest.php +++ b/tests/CheckTest.php @@ -6,12 +6,14 @@ use Vigilant\Check; use Vigilant\Feed\Details; use Vigilant\Config; +use Vigilant\Logger; use Vigilant\Fetch; #[CoversClass(Check::class)] #[UsesClass(Details::class)] #[UsesClass(Fetch::class)] #[UsesClass(Config::class)] +#[UsesClass(Logger::class)] #[UsesClass(Vigilant\Cache::class)] #[UsesClass(Vigilant\Output::class)] #[UsesClass(Vigilant\Message::class)] @@ -20,6 +22,7 @@ class CheckTest extends TestCase { private static Config $config; + private static Logger $logger; /** @var array $feed */ private array $feed = [ @@ -46,6 +49,8 @@ public static function setUpBeforeClass(): void $config->method('getCachePath')->willReturn(mockfs::getUrl('/')); $config->method('getTimezone')->willReturn('UTC'); self::$config = $config; + + self::$logger = new Logger('UTC'); } public function setup(): void @@ -59,7 +64,7 @@ public function setup(): void public function testIsDue(): void { $details = new Details($this->feed); - $check = new check($details, self::$config, new Fetch()); + $check = new check($details, new Fetch(), self::$config, self::$logger); $this->assertIsBool($check->isDue()); } @@ -69,7 +74,7 @@ public function testIsDue(): void public function testGetNextCheckDate(): void { $details = new Details($this->feed); - $check = new check($details, self::$config, new Fetch()); + $check = new check($details, new Fetch(), self::$config, self::$logger); $this->assertEquals('1970-01-01 00:00:00', $check->getNextCheckDate()); } @@ -88,7 +93,7 @@ public function testCheckFirstTime(): void ])); $details = new Details($this->feed); - $check = new check($details, self::$config, $fetch); + $check = new check($details, $fetch, self::$config, self::$logger); $this->expectOutputRegex('/First feed check, not sending notifications for found items/'); @@ -113,7 +118,8 @@ public function testCheckWithCache(): void ])); $details = new Details($this->feed); - $check = new check($details, self::$config, $fetch); + $check = new check($details, $fetch, self::$config, self::$logger); + $check = new check($details, $fetch, self::$config, self::$logger); $this->expectOutputRegex('/Found 1 new item\(s\)/'); @@ -143,7 +149,7 @@ public function testCheckFetchErrorMessage(): void 'handler' => GuzzleHttp\HandlerStack::create($mock) ])); $details = new Details($this->feed); - $check = new check($details, self::$config, $fetch); + $check = new check($details, $fetch, self::$config, self::$logger); $this->expectOutputRegex('/Failed to fetch/'); diff --git a/tests/FeedsTest.php b/tests/FeedsTest.php index 95c16196..3975b1c6 100644 --- a/tests/FeedsTest.php +++ b/tests/FeedsTest.php @@ -4,10 +4,12 @@ use PHPUnit\Framework\Attributes\UsesClass; use Vigilant\Feeds; use Vigilant\Config; +use Vigilant\Logger; use Vigilant\Exception\AppException; #[CoversClass(Feeds::class)] #[UsesClass(Config::class)] +#[UsesClass(Logger::class)] #[UsesClass(AppException::class)] #[UsesClass(Vigilant\Output::class)] #[UsesClass(Vigilant\Feed\Feed::class)] @@ -16,18 +18,23 @@ #[UsesClass(Vigilant\Exception\FeedsException::class)] class FeedsTest extends TestCase { + private static Logger $logger; + + public static function setUpBeforeClass(): void + { + self::$logger = new Logger('UTC'); + } + /** * Test get() */ public function testGet(): void { - $this->expectOutputRegex('/Loading feeds.yaml/'); - /** @var PHPUnit\Framework\MockObject\Stub&Config */ $config = $this->createStub(Config::class); $config->method('getFeedsPath')->willReturn(self::getSamplePath('feeds.yaml')); - $feeds = new Feeds($config); + $feeds = new Feeds($config, self::$logger); $this->assertIsArray($feeds->get()); $this->assertContainsOnlyInstancesOf('Vigilant\Feed\Details', $feeds->get()); @@ -44,9 +51,8 @@ public function testNoFeedsException(): void $this->expectException(AppException::class); $this->expectExceptionMessage('No feeds in feeds.yaml'); - $this->expectOutputRegex('/Loading feeds.yaml/'); - new Feeds($config); + new Feeds($config, self::$logger); } /** @@ -60,8 +66,7 @@ public function testInvalidYamlFile(): void $this->expectException(AppException::class); $this->expectExceptionMessage('A colon cannot be used in an unquoted mapping value'); - $this->expectOutputRegex('/Loading feeds.yaml/'); - new Feeds($config); + new Feeds($config, self::$logger); } } diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php new file mode 100644 index 00000000..5dca3a0d --- /dev/null +++ b/tests/LoggerTest.php @@ -0,0 +1,74 @@ +format('Y-m-d h:i:s P'); + + $this->expectOutputString(sprintf( + '[%s] %s %s', + $date, + 'Hello', + PHP_EOL + )); + + $logger = new Logger('UTC', 1); + $logger->info('Hello'); + } + + /** + * Test `error()` + */ + public function testError(): void + { + $this->expectOutputRegex('/Hello/'); + + $logger = new Logger('UTC', 1); + $logger->error('Hello'); + } + + /** + * Test `debug()` + */ + public function testDebug(): void + { + $this->expectOutputRegex('/Hello/'); + + $logger = new Logger('UTC', 2); + $logger->debug('Hello'); + } + + /** + * Test setting log level too low + */ + public function testLogLevelTooLow(): void + { + $logger = new Logger('UTC', -1); + + $reflection = new \ReflectionClass($logger); + $actual = $reflection->getProperty('logLevel')->getValue($logger); + + $this->assertEquals(1, $actual); + } + + /** + * Test setting log level too hight + */ + public function testLogLevelTooHigh(): void + { + $logger = new Logger('UTC', 3); + + $reflection = new \ReflectionClass($logger); + $actual = $reflection->getProperty('logLevel')->getValue($logger); + + $this->assertEquals(2, $actual); + } +} diff --git a/tests/Notification/GotifyTest.php b/tests/Notification/GotifyTest.php index ba9efde4..b5c5d48a 100644 --- a/tests/Notification/GotifyTest.php +++ b/tests/Notification/GotifyTest.php @@ -3,15 +3,19 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; +use Vigilant\Logger; use Vigilant\Notification\Gotify; use Vigilant\Exception\NotificationException; #[CoversClass(Gotify::class)] +#[UsesClass(Logger::class)] #[CoversClass(Vigilant\Notification\AbstractNotification::class)] #[UsesClass(NotificationException::class)] #[UsesClass(Vigilant\Output::class)] class GotifyTest extends TestCase { + private static Logger $logger; + /** @var array $config */ private array $config = [ 'server' => 'https://gotify.example.invalid', @@ -19,13 +23,18 @@ class GotifyTest extends TestCase 'priority' => 0, ]; + public static function setUpBeforeClass(): void + { + self::$logger = new Logger('UTC'); + } + /** * Test `setup()` */ #[DoesNotPerformAssertions] public function testSetup(): void { - new Gotify($this->config); + new Gotify($this->config, self::$logger); } /** @@ -36,7 +45,7 @@ public function testSend(): void $client = self::createStub(\Gotify\Endpoint\Message::class); $client->method('create')->willReturn(new stdClass()); - $gotify = new Gotify($this->config); + $gotify = new Gotify($this->config, self::$logger); $reflection = new ReflectionClass($gotify); $property = $reflection->getProperty('message'); @@ -53,7 +62,7 @@ public function testSendNotificationException(): void $this->expectException(NotificationException::class); $this->expectExceptionMessage('[Notification error] [Gotify]'); - $gotify = new Gotify($this->config); + $gotify = new Gotify($this->config, self::$logger); $gotify->send('Hello World', 'Hello from phpunit'); } } diff --git a/tests/Notification/NtfyTest.php b/tests/Notification/NtfyTest.php index 28bc9033..4eeceda1 100644 --- a/tests/Notification/NtfyTest.php +++ b/tests/Notification/NtfyTest.php @@ -3,15 +3,19 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; +use Vigilant\Logger; use Vigilant\Notification\Ntfy; use Vigilant\Exception\NotificationException; #[CoversClass(Ntfy::class)] +#[UsesClass(Logger::class)] #[CoversClass(Vigilant\Notification\AbstractNotification::class)] #[UsesClass(NotificationException::class)] #[UsesClass(Vigilant\Output::class)] class NtfyTest extends TestCase { + private static Logger $logger; + /** @var array $config */ private array $config = [ 'server' => 'https://ntfy.example.invalid', @@ -22,13 +26,18 @@ class NtfyTest extends TestCase ] ]; + public static function setUpBeforeClass(): void + { + self::$logger = new Logger('UTC'); + } + /** * Test `setup()` with no auth */ #[DoesNotPerformAssertions] public function testSetupWithNoAuth(): void { - new Ntfy($this->config); + new Ntfy($this->config, self::$logger); } /** @@ -41,7 +50,7 @@ public function testSetupWithPasswordAuth(): void $config['auth']['method'] = 'password'; $config['auth']['username'] = 'bob'; $config['auth']['password'] = 'qwerty'; - new Ntfy($config); + new Ntfy($config, self::$logger); } /** @@ -53,7 +62,7 @@ public function testSetupWithTokenAuth(): void $config = $this->config; $config['auth']['method'] = 'token'; $config['auth']['token'] = 'qwerty'; - new Ntfy($config); + new Ntfy($config, self::$logger); } /** @@ -64,7 +73,7 @@ public function testSend(): void $client = self::createStub(\Ntfy\Client::class); $client->method('send')->willReturn(new stdClass()); - $ntfy = new Ntfy($this->config); + $ntfy = new Ntfy($this->config, self::$logger); $reflection = new ReflectionClass($ntfy); $property = $reflection->getProperty('client'); @@ -81,7 +90,7 @@ public function testSendNotificationException(): void $this->expectException(NotificationException::class); $this->expectExceptionMessage('[Notification error] [Ntfy]'); - $ntfy = new Ntfy($this->config); + $ntfy = new Ntfy($this->config, self::$logger); $ntfy->send('Hello World', 'Hello from phpunit'); } } diff --git a/tests/NotifyTest.php b/tests/NotifyTest.php index d02f61fd..6d3a4ce2 100644 --- a/tests/NotifyTest.php +++ b/tests/NotifyTest.php @@ -6,6 +6,7 @@ use Vigilant\Feed\Details; use Vigilant\Config; use Vigilant\Message; +use Vigilant\Logger; use Vigilant\Notification\Gotify; use Vigilant\Notification\Ntfy; @@ -13,6 +14,7 @@ #[UsesClass(Details::class)] #[UsesClass(Config::class)] #[UsesClass(Message::class)] +#[UsesClass(Logger::class)] #[UsesClass(Gotify::class)] #[UsesClass(Ntfy::class)] #[UsesClass(Vigilant\Output::class)] @@ -20,6 +22,8 @@ #[UsesClass(Vigilant\Exception\NotificationException::class)] class NotifyTest extends TestCase { + private static Logger $logger; + /** @var array $feed */ private array $feed = [ 'name' => 'GitHub status', @@ -27,6 +31,11 @@ class NotifyTest extends TestCase 'interval' => 900 ]; + public static function setUpBeforeClass(): void + { + self::$logger = new Logger('UTC'); + } + public function testSend(): void { $this->expectOutputRegex('/Sent notification using Ntfy/'); @@ -42,7 +51,7 @@ public function testSend(): void new Message('Hello World', 'Hello??') ]; - $notify = new notify(new Details($this->feed), $config); + $notify = new notify(new Details($this->feed), $config, self::$logger); $notify->send($messages); } @@ -61,7 +70,7 @@ public function testSendWithNotificationError(): void new Message('Hello World', 'Hello??') ]; - $notify = new notify(new Details($this->feed), $config); + $notify = new notify(new Details($this->feed), $config, self::$logger); $notify->send($messages); } @@ -79,7 +88,7 @@ public function testCreatingGotify(): void $config->method('getGotifyPriority')->willReturn(0); $config->method('getGotifyToken')->willReturn('fake-token'); - $notify = new notify(new Details($this->feed), $config); + new notify(new Details($this->feed), $config, self::$logger); } /** @@ -99,7 +108,7 @@ public function testCreatingGotifyWithPriorityFromFeedDetails(): void $feed = $this->feed; $feed['gotify_priority'] = 5; - $notify = new notify(new Details($feed), $config); + new notify(new Details($feed), $config, self::$logger); } /** @@ -119,7 +128,7 @@ public function testCreatingGotifyWithTokenFromFeedDetails(): void $feed = $this->feed; $feed['gotify_token'] = 'qwerty'; - $notify = new notify(new Details($feed), $config); + new notify(new Details($feed), $config, self::$logger); } /** @@ -135,7 +144,7 @@ public function testCreatingNtfy(): void $config->method('getNtfyUrl')->willReturn('https://ntfy.example.com/'); $config->method('getNtfyPriority')->willReturn(0); - $notify = new notify(new Details($this->feed), $config); + new notify(new Details($this->feed), $config, self::$logger); } /** @@ -154,7 +163,7 @@ public function testCreatingNtfyWithPasswordAuth(): void $config->method('getNtfyUsername')->willReturn('bob'); $config->method('getNtfyPassword')->willReturn('qwerty'); - $notify = new notify(new Details($this->feed), $config); + new notify(new Details($this->feed), $config, self::$logger); } /** @@ -172,7 +181,7 @@ public function testCreatingNtfyWithTokenAuth(): void $config->method('getNtfyToken')->willReturn('fake-token'); $config->method('getNtfyAuthMethod')->willReturn('token'); - $notify = new notify(new Details($this->feed), $config); + new notify(new Details($this->feed), $config, self::$logger); } /** @@ -191,7 +200,7 @@ public function testCreatingNtfyWithTokenFromFeedDetails(): void $feed = $this->feed; $feed['ntfy_token'] = 'qwerty'; - $notify = new notify(new Details($feed), $config); + new notify(new Details($feed), $config, self::$logger); } /** @@ -210,7 +219,7 @@ public function testCreatingNtfyWithTopicFromFeedDetails(): void $feed = $this->feed; $feed['ntfy_topic'] = 'qwerty'; - $notify = new notify(new Details($feed), $config); + new notify(new Details($feed), $config, self::$logger); } /** @@ -229,6 +238,6 @@ public function testCreatingNtfyWithPriorityFromFeedDetails(): void $feed = $this->feed; $feed['ntfy_priority'] = 5; - $notify = new notify(new Details($feed), $config); + new notify(new Details($feed), $config, self::$logger); } } diff --git a/tests/OutputTest.php b/tests/OutputTest.php index d7767413..44a62a30 100644 --- a/tests/OutputTest.php +++ b/tests/OutputTest.php @@ -20,14 +20,4 @@ public function testOutput(): void Output::text($this->text); } - - /** - * Test newline() - */ - public function testNewline(): void - { - $this->expectOutputString(PHP_EOL); - - Output::newline(); - } } diff --git a/vigilant.php b/vigilant.php index 67d24cb4..af697b0d 100644 --- a/vigilant.php +++ b/vigilant.php @@ -6,6 +6,7 @@ use Vigilant\Fetch; use Vigilant\Notify; use Vigilant\Output; +use Vigilant\Logger; use Vigilant\Version; use Vigilant\Exception\ConfigException; use Vigilant\Exception\AppException; @@ -13,33 +14,34 @@ require('vendor/autoload.php'); try { - Output::text(sprintf('Vigilant version %s', Version::get())); - $config = new Config(); $config->validate(); + $logger = new Logger($config->getTimezone()); + $logger->debug(sprintf('Vigilant version %s', Version::get())); + $fetch = new Fetch(); - $feeds = new Feeds($config); - Output::newline(); + $feeds = new Feeds($config, $logger); foreach ($feeds->get() as $details) { - $notify = new Notify($details, $config); + $notify = new Notify($details, $config, $logger); $check = new Check( $details, + $fetch, $config, - $fetch + $logger ); if ($check->isDue() === true) { $check->check(); $notify->send($check->getMessages()); - } - Output::text(sprintf( - 'Next check in %s seconds at %s', - $details->getInterval(), - $check->getNextCheckDate() - )); + $logger->info(sprintf( + 'Next check in %s seconds at %s', + $details->getInterval(), + $check->getNextCheckDate() + )); + } } } catch (ConfigException | AppException $err) { Output::text($err->getMessage()); From e3de7ff61503b6fd3f770c985b9642299b58e733 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 29 Apr 2024 14:30:35 +0000 Subject: [PATCH 05/16] Add verbose environment variable (#173) Adds environment variable `VIGILANT_VERBOSE` to control logging. --- daemon.php | 6 +++++- docs/configuration.md | 6 ++++++ src/Config.php | 11 ++++++++++ src/Config/AbstractValidator.php | 10 +++++++++ src/Config/Validator.php | 17 ++++++++++++++++ tests/Config/AbstractValidatorTest.php | 12 +++++++++++ tests/Config/ValidatorTest.php | 28 ++++++++++++++++++++++++++ tests/ConfigTest.php | 12 +++++++++++ tests/TestCase.php | 1 + vigilant.php | 7 +++++-- 10 files changed, 107 insertions(+), 3 deletions(-) diff --git a/daemon.php b/daemon.php index 926addcc..7ae1ccbc 100644 --- a/daemon.php +++ b/daemon.php @@ -19,8 +19,12 @@ $config = new Config(); $config->validate(); + $logger = new Logger( + $config->getTimezone(), + $config->getLoggingLevel() + ); + $fetch = new Fetch(); - $logger = new Logger($config->getTimezone()); $feeds = new Feeds($config, $logger); /** @phpstan-ignore-next-line */ diff --git a/docs/configuration.md b/docs/configuration.md index 5e451b81..64e9c073 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -56,3 +56,9 @@ Vigilant can be used a with ntfy server that has password or [access token](http | `VIGILANT_NOTIFICATION_NTFY_USERNAME` | Ntfy authentication username. | | `VIGILANT_NOTIFICATION_NTFY_PASSWORD` | Ntfy authentication password. | | `VIGILANT_NOTIFICATION_NTFY_TOKEN` | Ntfy access token. | + +## Logging + +| Name | Description | +| ------------------ | --------------------------------------------------------------- | +| `VIGILANT_VERBOSE` | Enable additional logging. Supported values: `true` or `false`. | \ No newline at end of file diff --git a/src/Config.php b/src/Config.php index fc941c3f..a045a46e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -25,6 +25,7 @@ class Config /** @var array $defaults Default values for config parameters */ private array $defaults = [ + 'logging_level' => 1, 'feeds_file' => 'feeds.yaml', 'notification_gotify_priority' => 4, 'notification_ntfy_priority' => 3, @@ -51,6 +52,7 @@ public function validate(): void { $this->requireConfigFile(); + $this->validate->verbose(); $this->validate->timezone(); $this->validate->folder($this->getCachePath()); $this->validate->feedsFile(); @@ -58,6 +60,15 @@ public function validate(): void $this->config = $this->validate->getConfig(); } + /** + * Return logging level + * @return int + */ + public function getLoggingLevel(): int + { + return $this->config['logging_level']; + } + /** * Returns timezone * diff --git a/src/Config/AbstractValidator.php b/src/Config/AbstractValidator.php index a7b9e2d0..7320d68b 100644 --- a/src/Config/AbstractValidator.php +++ b/src/Config/AbstractValidator.php @@ -27,6 +27,16 @@ public function getConfig(): array return $this->config; } + /** + * Check if a environment variable is a boolean + * + * @param string $name Variable name excluding prefix + */ + public function isEnvBoolean(string $name): bool + { + return in_array($this->getEnv($name), ['true', 'false']); + } + /** * Check for an environment variable * diff --git a/src/Config/Validator.php b/src/Config/Validator.php index eb940063..21528a7a 100644 --- a/src/Config/Validator.php +++ b/src/Config/Validator.php @@ -53,6 +53,23 @@ public function folder(string $path): void } } + /** + * Validate `VIGILANT_VERBOSE` + * @throws ConfigException if value is not a boolean + */ + public function verbose(): void + { + if ($this->hasEnv('VERBOSE') === true) { + if ($this->isEnvBoolean('VERBOSE') === false) { + throw new ConfigException('Verbose environment variable value must a boolean [VIGILANT_VERBOSE]'); + } + + if ($this->getEnv('VERBOSE') === 'true') { + $this->config['logging_level'] = 2; + } + } + } + /** * Validate `VIGILANT_TIMEZONE` * @throws ConfigException if invalid timezone is given diff --git a/tests/Config/AbstractValidatorTest.php b/tests/Config/AbstractValidatorTest.php index 530e4927..eaa264e3 100644 --- a/tests/Config/AbstractValidatorTest.php +++ b/tests/Config/AbstractValidatorTest.php @@ -18,6 +18,18 @@ public function testGetConfig(): void $this->assertEquals($expected, $class->getConfig()); } + /** + * Test `isEnvBoolean` + */ + public function testIsEnvBoolean(): void + { + putenv('VIGILANT_TEST=true'); + + $class = new class ([]) extends AbstractValidator { + }; + $this->assertTrue($class->isEnvBoolean('TEST')); + } + /** * Test `getEnv()` */ diff --git a/tests/Config/ValidatorTest.php b/tests/Config/ValidatorTest.php index 0cd269a9..7ac025ba 100644 --- a/tests/Config/ValidatorTest.php +++ b/tests/Config/ValidatorTest.php @@ -79,6 +79,34 @@ public function testExtensions(): void $validate->extensions(['pgp']); } + /** + * Test `verbose()` + */ + public function testVerbose(): void + { + putenv('VIGILANT_VERBOSE=true'); + + $validate = new Validator(self::$defaults); + $validate->verbose(); + $config = $validate->getConfig(); + + $this->assertEquals(2, $config['logging_level']); + } + + /** + * Test `verbose()` with `VIGILANT_VERBOSE` value not a boolean + */ + public function testVerboseNotBoolean(): void + { + $this->expectException(ConfigException::class); + $this->expectExceptionMessage('Verbose environment variable value must a boolean'); + + putenv('VIGILANT_VERBOSE=string'); + + $validate = new Validator(self::$defaults); + $validate->verbose(); + } + /** * Test `timezone()` */ diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 0a0f8e50..5a26a050 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -42,6 +42,18 @@ public function testValidate(): void $this->assertEquals('hello', $config->getNtfyTopic()); } + /** + * Test `getLoggingLevel()` + */ + public function testGetLoggingLevel(): void + { + $config = new Config(); + $this->assertEquals( + self::$defaults['logging_level'], + $config->getLoggingLevel() + ); + } + /** * Test `getTimezone()` */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 2d050251..8ae9fbf3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -36,6 +36,7 @@ protected static function getSamplePath(string $name): string protected function resetEnvs(): void { // Unset environment variables before each test + putenv('VIGILANT_VERBOSE'); putenv('VIGILANT_TIMEZONE'); putenv('VIGILANT_FEEDS_FILE'); putenv('VIGILANT_NOTIFICATION_SERVICE'); diff --git a/vigilant.php b/vigilant.php index af697b0d..36f7ad2f 100644 --- a/vigilant.php +++ b/vigilant.php @@ -17,8 +17,11 @@ $config = new Config(); $config->validate(); - $logger = new Logger($config->getTimezone()); - $logger->debug(sprintf('Vigilant version %s', Version::get())); + $logger = new Logger( + $config->getTimezone(), + $config->getLoggingLevel() + ); + $logger->debug(sprintf('Vigilant v%s', Version::get())); $fetch = new Fetch(); $feeds = new Feeds($config, $logger); From cbabe5b2cba15135e068410db0126a6782167ecb Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 29 Apr 2024 14:34:42 +0000 Subject: [PATCH 06/16] dependabot: Add main dockerfile (#177) --- .github/dependabot.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 78910418..1eead900 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,6 +13,11 @@ updates: schedule: interval: "monthly" + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "monthly" + # dev container - package-ecosystem: "docker" directory: "/.devcontainer/workspace/" From 898532a9b58e5ad7a07b1f5600cbc57cfa4a1877 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:36:57 +0000 Subject: [PATCH 07/16] Bump composer from 2.7.2 to 2.7.4 in /.devcontainer/workspace (#180) --- .devcontainer/workspace/dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/workspace/dockerfile b/.devcontainer/workspace/dockerfile index 37080a1c..5a150d3e 100644 --- a/.devcontainer/workspace/dockerfile +++ b/.devcontainer/workspace/dockerfile @@ -1,4 +1,4 @@ -FROM composer:2.7.2 AS composer +FROM composer:2.7.4 AS composer FROM php:8.2.18-cli-alpine3.19 RUN apk add --update --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \ From 2ffc19a4f39fd286901389f3729c7e8ca0e5c917 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:37:09 +0000 Subject: [PATCH 08/16] Bump shivammathur/setup-php from 2.30.2 to 2.30.4 (#178) --- .github/workflows/build.yml | 2 +- .github/workflows/code-quality.yml | 4 ++-- .github/workflows/test.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c14f6c68..e7a10141 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,7 +60,7 @@ jobs: uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 - name: Setup PHP - uses: shivammathur/setup-php@8872c784b04a1420e81191df5d64fbd59d3d3033 # v2.30.2 + uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 with: php-version: '8.1' coverage: none diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 0cda5bfc..a6b10ae2 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 - name: Setup PHP - uses: shivammathur/setup-php@8872c784b04a1420e81191df5d64fbd59d3d3033 # v2.30.2 + uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 with: php-version: '8.1' coverage: none @@ -44,7 +44,7 @@ jobs: uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 - name: Setup PHP - uses: shivammathur/setup-php@8872c784b04a1420e81191df5d64fbd59d3d3033 # v2.30.2 + uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 with: php-version: '8.1' coverage: none diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bd4820c8..af09269c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 - name: Setup PHP - uses: shivammathur/setup-php@8872c784b04a1420e81191df5d64fbd59d3d3033 # v2.30.2 + uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 with: php-version: '8.1' coverage: xdebug From 91078ea53f15b4ae96852e697560e56bccd16306 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:38:22 +0000 Subject: [PATCH 09/16] Bump phpunit/phpunit from 10.5.19 to 10.5.20 (#174) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 65b169c8..178b13d0 100644 --- a/composer.lock +++ b/composer.lock @@ -1911,16 +1911,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.19", + "version": "10.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c726f0de022368f6ed103e452a765d3304a996a4" + "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c726f0de022368f6ed103e452a765d3304a996a4", - "reference": "c726f0de022368f6ed103e452a765d3304a996a4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/547d314dc24ec1e177720d45c6263fb226cc2ae3", + "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3", "shasum": "" }, "require": { @@ -1992,7 +1992,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.20" }, "funding": [ { @@ -2008,7 +2008,7 @@ "type": "tidelift" } ], - "time": "2024-04-17T14:06:18+00:00" + "time": "2024-04-24T06:32:35+00:00" }, { "name": "sebastian/cli-parser", From 1fe786950f020bf8b7da6a80ef5f3f23a66e0557 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:38:52 +0000 Subject: [PATCH 10/16] Bump actions/upload-artifact from 4.3.2 to 4.3.3 (#179) --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7a10141..0ca4e7ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: run: bash ./build/build-dist.sh - name: Upload artifact - uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # v4.3.2 + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 with: name: vigilant-${{ github.REF_NAME }} path: dist/ From de92b11fd4a0be6dbcad65dc7ab689790e339b42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:39:16 +0000 Subject: [PATCH 11/16] Bump actions/checkout from 4.1.3 to 4.1.4 (#181) --- .github/workflows/build.yml | 4 ++-- .github/workflows/code-quality.yml | 4 ++-- .github/workflows/test.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ca4e7ef..c2df44a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Set up QEMU uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 @@ -57,7 +57,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Setup PHP uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index a6b10ae2..859336be 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Setup PHP uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Setup PHP uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af09269c..2142697a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Setup PHP uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4 From e5b096ffd94e06accec1642b168a3415a383f64e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:39:32 +0000 Subject: [PATCH 12/16] Bump squizlabs/php_codesniffer from 3.9.1 to 3.9.2 (#176) --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 178b13d0..a77b1f29 100644 --- a/composer.lock +++ b/composer.lock @@ -2928,16 +2928,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.1", + "version": "3.9.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909" + "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/267a4405fff1d9c847134db3a3c92f1ab7f77909", - "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/aac1f6f347a5c5ac6bc98ad395007df00990f480", + "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480", "shasum": "" }, "require": { @@ -3004,7 +3004,7 @@ "type": "open_collective" } ], - "time": "2024-03-31T21:03:09+00:00" + "time": "2024-04-23T20:25:34+00:00" }, { "name": "theseer/tokenizer", From 14321247797e584ae56633f3b36cebb7e8c85421 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:41:26 +0000 Subject: [PATCH 13/16] Bump composer from 2.7.2 to 2.7.4 (#182) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c2258418..bbdabbd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM composer:2.7.2 AS composer +FROM composer:2.7.4 AS composer COPY ./ /app WORKDIR /app From e4b874e1a383ccb4347964b04074450cd74aebb2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:41:43 +0000 Subject: [PATCH 14/16] Bump symfony/yaml from 6.4.3 to 6.4.7 (#175) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index a77b1f29..10de9b53 100644 --- a/composer.lock +++ b/composer.lock @@ -1070,16 +1070,16 @@ }, { "name": "symfony/yaml", - "version": "v6.4.3", + "version": "v6.4.7", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "d75715985f0f94f978e3a8fa42533e10db921b90" + "reference": "53e8b1ef30a65f78eac60fddc5ee7ebbbdb1dee0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/d75715985f0f94f978e3a8fa42533e10db921b90", - "reference": "d75715985f0f94f978e3a8fa42533e10db921b90", + "url": "https://api.github.com/repos/symfony/yaml/zipball/53e8b1ef30a65f78eac60fddc5ee7ebbbdb1dee0", + "reference": "53e8b1ef30a65f78eac60fddc5ee7ebbbdb1dee0", "shasum": "" }, "require": { @@ -1122,7 +1122,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v6.4.3" + "source": "https://github.com/symfony/yaml/tree/v6.4.7" }, "funding": [ { @@ -1138,7 +1138,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-28T10:28:08+00:00" }, { "name": "verifiedjoseph/gotify-api-php", From 3a2db0afb1d32e0d8079b181a4f758d32b52d963 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 29 Apr 2024 15:24:07 +0000 Subject: [PATCH 15/16] Fix fatal error when calling Config method `getNtfyAuthMethod()` (#183) Fix fatal error when calling Config method `getNtfyAuthMethod()` if no Ntfy auth method is set. --- src/Config.php | 1 + tests/ConfigTest.php | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Config.php b/src/Config.php index a045a46e..0cd21eaf 100644 --- a/src/Config.php +++ b/src/Config.php @@ -29,6 +29,7 @@ class Config 'feeds_file' => 'feeds.yaml', 'notification_gotify_priority' => 4, 'notification_ntfy_priority' => 3, + 'notification_ntfy_auth' => 'none' ]; /** @var array $config Loaded config parameters */ diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 5a26a050..3b918463 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -129,13 +129,7 @@ public function testGetNtfyPriority(): void public function testGetNtfyAuthMethod(): void { $config = new Config(); - - $reflection = new ReflectionClass($config); - $property = $reflection->getProperty('config'); - $property->setAccessible(true); - $property->setValue($config, ['notification_ntfy_auth' => 'password']); - - $this->assertEquals('password', $config->getNtfyAuthMethod()); + $this->assertEquals('none', $config->getNtfyAuthMethod()); } /** From 301e742f554f829b56bc9ec65f1c3291ac503beb Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 29 Apr 2024 15:48:50 +0000 Subject: [PATCH 16/16] Version 1.2.0 (#184) --- CHANGELOG.md | 10 ++++++++++ docker-compose.yml | 2 +- docs/install.md | 2 +- src/Version.php | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b9c3e9..9dd32c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project are documented in this file. +## [1.2.0](https://github.com/VerifiedJoseph/vigilant/releases/tag/v1.2.0) - 2024-04-29 + +- Fixed fatal error when calling Config class method `getNtfyAuthMethod()`. ([#183](https://github.com/VerifiedJoseph/vigilant/pull/183), [`3a2db0a`](https://github.com/VerifiedJoseph/vigilant/commit/3a2db0afb1d32e0d8079b181a4f758d32b52d963)) +- Added environment variable `VIGILANT_VERBOSE` to control logging. ([#173](https://github.com/VerifiedJoseph/vigilant/pull/173), [`e3de7ff`](https://github.com/VerifiedJoseph/vigilant/commit/e3de7ff61503b6fd3f770c985b9642299b58e733)) +- Added Logger class. ([#172](https://github.com/VerifiedJoseph/vigilant/pull/172), [`b696629`](https://github.com/VerifiedJoseph/vigilant/commit/b696629bc82d791c55813367621a88436a2d99e8)) +- Dockerfile: Updated composer from 2.7.2 to 2.7.4 ([#182](https://github.com/VerifiedJoseph/vigilant/pull/182), [`1432124`](https://github.com/VerifiedJoseph/vigilant/commit/14321247797e584ae56633f3b36cebb7e8c85421)) +- Composer: Updated symfony/yaml from 6.4.3 to 6.4.7 ([#175](https://github.com/VerifiedJoseph/vigilant/pull/175), [`e4b874e`](https://github.com/VerifiedJoseph/vigilant/commit/e4b874e1a383ccb4347964b04074450cd74aebb2)) + +All changes: https://github.com/VerifiedJoseph/vigilant/compare/v1.1.0...v1.2.0 + ## [1.1.0](https://github.com/VerifiedJoseph/vigilant/releases/tag/v1.1.0) - 2024-04-19 - Re-implemented docker. ([#154](https://github.com/VerifiedJoseph/vigilant/pull/154), [`9b6b8d3`](https://github.com/VerifiedJoseph/vigilant/commit/9b6b8d3660053de8277ab3bf2c74815460e066af)) diff --git a/docker-compose.yml b/docker-compose.yml index 3358b034..a8250556 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: vigilant: - image: ghcr.io/verifiedjoseph/vigilant:1.1.0 + image: ghcr.io/verifiedjoseph/vigilant:1.2.0 environment: - VIGILANT_TIMEZONE=Europe/London - VIGILANT_NOTIFICATION_SERVICE=ntfy diff --git a/docs/install.md b/docs/install.md index 1f5635dc..11dad42d 100644 --- a/docs/install.md +++ b/docs/install.md @@ -6,7 +6,7 @@ version: '3' services: vigilant: - image: ghcr.io/verifiedjoseph/vigilant:1.1.0 + image: ghcr.io/verifiedjoseph/vigilant:1.2.0 environment: - VIGILANT_NOTIFICATION_SERVICE=ntfy - VIGILANT_NOTIFICATION_NTFY_URL=https://ntfy.sh/ diff --git a/src/Version.php b/src/Version.php index c2adb5b6..adae34a3 100644 --- a/src/Version.php +++ b/src/Version.php @@ -7,7 +7,7 @@ class Version /** * @var string $version Vigilant version */ - private static string $version = '1.1.0'; + private static string $version = '1.2.0'; /** * Returns version number