Skip to content

Commit

Permalink
Fixed error in generating HMTL when transferring to Telegram via Jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Mar 23, 2024
1 parent ce91429 commit 93a6d80
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/Data/Casts/ChangelogCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class ChangelogCast implements Cast
'allow_unsafe_links' => false,
];

protected array $tagsFrom = ['h2', '<li>'];
protected array $tagsFrom = ['h2', '<li>', '</li>'];

protected array $tagsTo = ['b', '- '];
protected array $tagsTo = ['b', '- ', ''];

protected string $allowedTags = '<h2><li><i>';
protected array $allowedTags = ['h2', 'li', 'i'];

public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string
{
Expand Down
15 changes: 12 additions & 3 deletions app/Jobs/Telegram/ReleaseJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Jobs\Telegram;

use App\Data\ReleaseData;
use App\Jobs\Job;
use DefStudio\Telegraph\Models\TelegraphChat;
use Throwable;
Expand All @@ -15,7 +14,11 @@ class ReleaseJob extends Job

public function __construct(
public int $chatId,
public ReleaseData $data
public string $organization,
public string $repository,
public string $version,
public string $changelog,
public string $url
) {}

public function handle(): void
Expand All @@ -38,7 +41,13 @@ protected function send(): void

protected function message(): string
{
return view('message', ['release' => $this->data])->toHtml();
return view('message', [
'organization' => $this->organization,
'repository' => $this->repository,
'version' => $this->version,
'changelog' => $this->changelog,
'url' => $this->url,
])->toHtml();
}

protected function resetErrors(): void
Expand Down
9 changes: 8 additions & 1 deletion app/Services/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ class Telegram
public function publish(ReleaseData $data): void
{
$this->chats()->each(
fn (TelegraphChat $chat) => ReleaseJob::dispatch($chat->id, $data)
fn (TelegraphChat $chat) => ReleaseJob::dispatch(
$chat->id,
$data->organization,
$data->repository,
$data->version,
$data->changelog,
$data->url
)
);
}

Expand Down
6 changes: 3 additions & 3 deletions resources/views/message.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<b>{{ $release->organization }} {{ $release->repository }} {{ $release->version }} released</b>
<b>{{ $organization }} {{ $repository }} {{ $version }} released</b>

{!! $release->changelog !!}
{!! $changelog !!}

{{ $release->url }}
{{ $url }}

0 comments on commit 93a6d80

Please sign in to comment.