Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
php: [ '8.1', '8.2', '8.3' ]
php: [ '8.4', '8.5' ]

steps:
- uses: actions/checkout@v6
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/setup_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
php: [ '8.1', '8.2', '8.3' ]
laravel: [ 11.*, 10.*, 9.* ]
php: [ '8.4', '8.5' ]
laravel: [ 12.*, 11.* ]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
exclude:
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: 8.4
- laravel: 12.*
php: 8.5
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:
override: [ php-scrutinizer-run ]
environment:
php:
version: 8.2
version: 8.3

checks:
php:
Expand Down
20 changes: 9 additions & 11 deletions common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @return string|null
*/
function tgn_singularity(string $word): string|null
function tgn_singularity(string $word): ?string
{
static $singular_rules = [
'/(quiz)zes$/i' => '$1',
Expand Down Expand Up @@ -56,7 +56,7 @@ function tgn_singularity(string $word): string|null
*/
function tgn_snake_case(string $string): string
{
$string = preg_replace('/\s+/', '_', $string);
$string = preg_replace('/\s+/', '_', $string) ?? $string;

return strtolower($string);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ function tgn_convert_event_name(string $event): string
*/
function tgn_convert_action_name(string $action): string
{
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $action));
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $action) ?? $action);
}
}

Expand Down Expand Up @@ -128,28 +128,26 @@ function config(string $string): mixed
*
* @return null|string
*/
function view(string $partialPath, array $data = []): null|string
function view(string $partialPath, array $data = []): ?string
{
$content = (new ConfigHelper())->getTemplateData(
$partialPath,
$data
);

return $content ?: null;
return $content !== '' ? $content : null;
}
}
}

if (!function_exists('tgn_view')) {
/**
* Get view template
* Get view template from the correct source (Laravel Blade or standalone PHP).
*
* @param string $partialPath
* @param array $data
*
* @noinspection PhpMissingReturnTypeInspection
* @param string $partialPath Dot-notation template path
* @param array<string, mixed> $data Variables to pass to the template
*/
function tgn_view(string $partialPath, array $data = [])
function tgn_view(string $partialPath, array $data = []): mixed
{
if (class_exists('Illuminate\Foundation\Application')) {
$partialPath = config('telegram-git-notifier.view.namespace') . '::' . $partialPath;
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"php": "^8.4|^8.5",
"eleirbag89/telegrambotphp": "^1.4",
"guzzlehttp/guzzle": "^7.8",
"psr/log": "^3.0",
"symfony/http-foundation": "^7.0",
"vlucas/phpdotenv": "^5.6"
},
Expand Down
Empty file modified config/jsons/github-events.json
100644 → 100755
Empty file.
Empty file modified config/jsons/gitlab-events.json
100644 → 100755
Empty file.
Empty file modified config/jsons/tgn-settings.json
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ parameters:
- src
- config
tmpDir: build/phpstan
checkMissingIterableValueType: false
12 changes: 6 additions & 6 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CSlant\TelegramGitNotifier;

use CSlant\TelegramGitNotifier\Constants\EventConstant;
use CSlant\TelegramGitNotifier\Enums\Platform;
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
use CSlant\TelegramGitNotifier\Interfaces\BotInterface;
use CSlant\TelegramGitNotifier\Models\Event;
Expand Down Expand Up @@ -39,12 +39,12 @@ class Bot implements BotInterface
* @throws ConfigFileException
*/
public function __construct(
Telegram $telegram = null,
?Telegram $telegram = null,
?string $chatBotId = null,
Event $event = null,
?string $platform = EventConstant::DEFAULT_PLATFORM,
?Event $event = null,
?string $platform = Platform::DEFAULT,
?string $platformFile = null,
Setting $setting = null,
?Setting $setting = null,
?string $settingFile = null,
) {
$this->event = $event ?? new Event();
Expand All @@ -61,7 +61,7 @@ public function __construct(

public function validateSettingFile(): void
{
if (empty($this->setting->getSettingFile())) {
if ($this->setting->getSettingFile() === '') {
throw ConfigFileException::settingFile($this->setting->getSettingFile());
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/Constants/EventConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,9 @@

final class EventConstant
{
public const DEFAULT_PLATFORM = 'github';

public const WEBHOOK_EVENT_HEADER = [
'github' => 'HTTP_X_GITHUB_EVENT',
'gitlab' => 'HTTP_X_GITLAB_EVENT',
];

public const EVENT_PREFIX = SettingConstant::SETTING_CUSTOM_EVENTS . '.evt.';

public const GITHUB_EVENT_SEPARATOR = 'gh.';

public const GITLAB_EVENT_SEPARATOR = 'gl.';

public const EVENT_HAS_ACTION_SEPARATOR = 'atc.';

public const EVENT_UPDATE_SEPARATOR = '.eus';

public const PLATFORM_EVENT_SEPARATOR = [
'github' => self::GITHUB_EVENT_SEPARATOR,
'gitlab' => self::GITLAB_EVENT_SEPARATOR,
];
}
26 changes: 13 additions & 13 deletions src/Constants/SettingConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

final class SettingConstant
{
public const SETTING_PREFIX = 'stg.';
public const string SETTING_PREFIX = 'stg.';

public const T_IS_NOTIFIED = 'is_notified';
public const string T_IS_NOTIFIED = 'is_notified';

public const T_ALL_EVENTS_NOTIFICATION = 'all_events_notify';
public const string T_ALL_EVENTS_NOTIFICATION = 'all_events_notify';

public const SETTING_IS_NOTIFIED = self::SETTING_PREFIX . self::T_IS_NOTIFIED;
public const string SETTING_IS_NOTIFIED = self::SETTING_PREFIX . self::T_IS_NOTIFIED;

public const SETTING_ALL_EVENTS_NOTIFY = self::SETTING_PREFIX . self::T_ALL_EVENTS_NOTIFICATION;
public const string SETTING_ALL_EVENTS_NOTIFY = self::SETTING_PREFIX . self::T_ALL_EVENTS_NOTIFICATION;

public const SETTING_CUSTOM_EVENTS = self::SETTING_PREFIX . 'cus';
public const string SETTING_CUSTOM_EVENTS = self::SETTING_PREFIX . 'cus';

public const SETTING_GITHUB_EVENTS = self::SETTING_CUSTOM_EVENTS . EventConstant::GITHUB_EVENT_SEPARATOR;
public const string SETTING_GITHUB_EVENTS = self::SETTING_CUSTOM_EVENTS . 'gh.';

public const SETTING_GITLAB_EVENTS = self::SETTING_CUSTOM_EVENTS . EventConstant::GITLAB_EVENT_SEPARATOR;
public const string SETTING_GITLAB_EVENTS = self::SETTING_CUSTOM_EVENTS . 'gl.';

public const BTN_LINE_ITEM_COUNT = 2;
public const int BTN_LINE_ITEM_COUNT = 2;

public const SETTING_BACK = self::SETTING_PREFIX . 'back.';
public const string SETTING_BACK = self::SETTING_PREFIX . 'back.';

public const SETTING_BACK_TO_MAIN_MENU = self::SETTING_BACK . 'menu';
public const string SETTING_BACK_TO_MAIN_MENU = self::SETTING_BACK . 'menu';

public const SETTING_BACK_TO_EVENTS_MENU = self::SETTING_BACK . 'settings.custom_events';
public const string SETTING_BACK_TO_EVENTS_MENU = self::SETTING_BACK . 'settings.custom_events';

public const SETTING_BACK_TO_SETTINGS_MENU = self::SETTING_BACK . 'settings';
public const string SETTING_BACK_TO_SETTINGS_MENU = self::SETTING_BACK . 'settings';
}
51 changes: 51 additions & 0 deletions src/DTOs/ChatTarget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace CSlant\TelegramGitNotifier\DTOs;

readonly class ChatTarget
{
/**
* @param string $chatId
* @param list<string> $threadIds
*/
public function __construct(
public string $chatId,
public array $threadIds = [],
) {
}

public function hasThreads(): bool
{
return $this->threadIds !== [];
}

/**
* Parse a single "chatId:thread1,thread2" string.
*/
public static function fromString(string $raw): self
{
[$chatId, $threadIds] = explode(':', $raw) + [null, null];

return new self(
chatId: (string) $chatId,
threadIds: $threadIds ? explode(',', $threadIds) : [],
);
}

/**
* Parse "id1;id2:t1,t2;id3" format into an array of ChatTarget.
*
* @return list<self>
*/
public static function parseMultiple(string $raw): array
{
if (trim($raw) === '') {
return [];
}

return array_map(
static fn (string $pair) => self::fromString($pair),
explode(';', $raw),
);
}
}
54 changes: 54 additions & 0 deletions src/Enums/Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace CSlant\TelegramGitNotifier\Enums;

enum Platform: string
{
case GITHUB = 'github';
case GITLAB = 'gitlab';

public const DEFAULT = 'github';

public function eventSeparator(): string
{
return match ($this) {
self::GITHUB => 'gh.',
self::GITLAB => 'gl.',
};
}

public function webhookEventHeader(): string
{
return match ($this) {
self::GITHUB => 'HTTP_X_GITHUB_EVENT',
self::GITLAB => 'HTTP_X_GITLAB_EVENT',
};
}

/**
* @return array<string, string>
*/
public static function webhookEventHeaders(): array
{
return array_combine(
array_map(fn (self $p) => $p->value, self::cases()),
array_map(fn (self $p) => $p->webhookEventHeader(), self::cases()),
);
}

/**
* @return array<string, string>
*/
public static function eventSeparators(): array
{
return array_combine(
array_map(fn (self $p) => $p->value, self::cases()),
array_map(fn (self $p) => $p->eventSeparator(), self::cases()),
);
}

public static function default(): self
{
return self::GITHUB;
}
Comment on lines +27 to +53

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Platform enum introduces methods webhookEventHeaders(), eventSeparators(), and default() that are never called anywhere in the codebase. Additionally, the data they return (webhook event headers and event separators) duplicates what's already in EventConstant::WEBHOOK_EVENT_HEADER and EventConstant::PLATFORM_EVENT_SEPARATOR. This creates a maintenance burden since both places need to stay in sync when new platforms are added. If the enum is the canonical source of truth, the constants should be removed and replaced with enum usages. If constants are canonical, the static methods on the enum are redundant.

Suggested change
/**
* @return array<string, string>
*/
public static function webhookEventHeaders(): array
{
return array_combine(
array_map(fn (self $p) => $p->value, self::cases()),
array_map(fn (self $p) => $p->webhookEventHeader(), self::cases()),
);
}
/**
* @return array<string, string>
*/
public static function eventSeparators(): array
{
return array_combine(
array_map(fn (self $p) => $p->value, self::cases()),
array_map(fn (self $p) => $p->eventSeparator(), self::cases()),
);
}
public static function default(): self
{
return self::GitHub;
}

Copilot uses AI. Check for mistakes.
}
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidViewTemplateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class InvalidViewTemplateException extends TelegramGitNotifierException
{
public static function create(
string $view,
Throwable $previous = null
?Throwable $previous = null
): self {
return new self(
"Invalid view template: {$view}",
Expand Down
Loading
Loading