diff --git a/app/Data/Casts/ChangelogCast.php b/app/Data/Casts/ChangelogCast.php index 30d3f45..b1c178c 100644 --- a/app/Data/Casts/ChangelogCast.php +++ b/app/Data/Casts/ChangelogCast.php @@ -3,6 +3,7 @@ namespace App\Data\Casts; use Illuminate\Support\Str; +use Illuminate\Support\Stringable; use Spatie\LaravelData\Casts\Cast; use Spatie\LaravelData\Support\Creation\CreationContext; use Spatie\LaravelData\Support\DataProperty; @@ -34,11 +35,17 @@ class ChangelogCast implements Cast protected string $resolveSpaces = '/
  • \n?\s*(.+)\n?\s*<\/li>/'; + public function __construct( + protected bool $short = false + ) { + } + public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): string { return Str::of($this->removeEmojis($value)) ->replaceMatches([$this->from, $this->fullLink], '') ->replaceMatches($this->contributors, $this->contributor) + ->when($this->short, fn (Stringable $str) => $str->limit(3500, preserveWords: true)) ->trim() ->markdown($this->options) ->replaceMatches($this->resolveSpaces, '
  • $1
  • ') diff --git a/app/Data/ReleaseData.php b/app/Data/ReleaseData.php index 0fde76d..443faf8 100644 --- a/app/Data/ReleaseData.php +++ b/app/Data/ReleaseData.php @@ -29,4 +29,8 @@ class ReleaseData extends Data #[MapInputName('release.body')] #[WithCast(ChangelogCast::class)] public string $changelog; + + #[MapInputName('release.body_short')] + #[WithCast(ChangelogCast::class, true)] + public string $shortChangelog; } diff --git a/app/Http/Requests/ReleaseRequest.php b/app/Http/Requests/ReleaseRequest.php index 44aff68..498d3d4 100644 --- a/app/Http/Requests/ReleaseRequest.php +++ b/app/Http/Requests/ReleaseRequest.php @@ -39,4 +39,11 @@ public function rules(): array 'repository.is_template' => ['required', 'bool', 'declined'], ]; } + + protected function prepareForValidation(): void + { + $this->mergeIfMissing([ + 'release.body_short' => $this->get('release')['body'] ?? '', + ]); + } } diff --git a/app/Services/Release.php b/app/Services/Release.php index 6e7a805..4e416d3 100644 --- a/app/Services/Release.php +++ b/app/Services/Release.php @@ -25,7 +25,7 @@ protected function publishToTelegram(ReleaseData $data): void $chat->id, $data->repository, $data->version, - $data->changelog, + $data->shortChangelog, $data->url ) );