Skip to content

Commit

Permalink
Merge pull request #81 from Laravel-Lang/2.x
Browse files Browse the repository at this point in the history
Message length limit for Telegram
  • Loading branch information
andrey-helldar authored Dec 20, 2024
2 parents 4ef9f38 + 8762b8f commit 2f83b6d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/Data/Casts/ChangelogCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,11 +35,17 @@ class ChangelogCast implements Cast

protected string $resolveSpaces = '/<li>\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, '<li>$1</li>')
Expand Down
4 changes: 4 additions & 0 deletions app/Data/ReleaseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions app/Http/Requests/ReleaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '',
]);
}
}
2 changes: 1 addition & 1 deletion app/Services/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function publishToTelegram(ReleaseData $data): void
$chat->id,
$data->repository,
$data->version,
$data->changelog,
$data->shortChangelog,
$data->url
)
);
Expand Down

0 comments on commit 2f83b6d

Please sign in to comment.