Skip to content

Commit

Permalink
fix: update gitlab event for bot setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Oct 20, 2023
1 parent ee9c053 commit fe36184
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Bot implements AppInterface, BotInterface, EventInterface, SettingInterfac
public function __construct(
Telegram $telegram = null,
?string $chatBotId = null,
Setting $setting = null,
Event $event = null,
?string $settingFile = null,
?string $platform = EventConstant::DEFAULT_PLATFORM,
?string $platformFile = null,
Setting $setting = null,
?string $settingFile = null,
) {
$this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token'));
$this->setCurrentChatBotId($chatBotId);
Expand Down
35 changes: 24 additions & 11 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ trait EventSettingTrait
{
public function eventMarkup(
?string $parentEvent = null,
string $platform = EventConstant::DEFAULT_PLATFORM
string $platform = EventConstant::DEFAULT_PLATFORM,
string $platformFile = null
): array {
$replyMarkup = $replyMarkupItem = [];

$this->event->setEventConfig($platform);
$this->setPlatFormForEvent($platform, $platformFile);

$events = $parentEvent === null ? $this->event->getEventConfig()
: $this->event->getEventConfig()[$parentEvent];

Expand Down Expand Up @@ -96,7 +98,8 @@ public function getEndKeyboard(

public function eventHandle(
?string $callback = null,
?string $platform = null
?string $platform = null,
?string $platFormFile = null
): void {
$platform = $this->getPlatformFromCallback($callback, $platform);

Expand All @@ -110,7 +113,7 @@ public function eventHandle(
return;
}

$this->handleEventUpdate($event, $platform);
$this->handleEventUpdate($event, $platform, $platFormFile);
}

public function getPlatformFromCallback(
Expand Down Expand Up @@ -185,23 +188,33 @@ public function handleEventWithActions(
return false;
}

public function handleEventUpdate(string $event, string $platform): void
{
public function handleEventUpdate(
string $event,
string $platform,
string $platFormFile = null
): void {
if (str_contains($event, EventConstant::EVENT_UPDATE_SEPARATOR)) {
$event = str_replace(
EventConstant::EVENT_UPDATE_SEPARATOR,
'',
$event
);
$this->eventUpdateHandle($event, $platform);
$this->eventUpdateHandle($event, $platform, $platFormFile);
}
}

public function eventUpdateHandle(string $event, string $platform): void
{
[$event, $action] = explode('.', $event);
public function eventUpdateHandle(
string $event,
string $platform,
string $platFormFile = null
): void {
if (str_contains($event, '.')) {
[$event, $action] = explode('.', $event);
} else {
$action = null;
}

$this->event->setEventConfig($platform);
$this->setPlatFormForEvent($platform);
$this->event->updateEvent($event, $action);
$this->eventHandle(
$action
Expand Down
8 changes: 3 additions & 5 deletions src/Trait/EventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ trait EventTrait

public function setPlatFormForEvent(string $platform, string $platformFile = null): void
{
if (!$this->event->getPlatformFile()) {
/** @var array $platformFileDefaults */
$platformFileDefaults = config('telegram-git-notifier.data_file.platform');
$this->event->setPlatformFile($platformFile ?? $platformFileDefaults[$platform]);
}
/** @var array $platformFileDefaults */
$platformFileDefaults = config('telegram-git-notifier.data_file.platform');
$this->event->setPlatformFile($platformFile ?? $platformFileDefaults[$platform]);
$this->event->setEventConfig($platform);
}

Expand Down

0 comments on commit fe36184

Please sign in to comment.