-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add Rule "description template" (#65)
* Add DescriptionTemplateRule * remove has_any_labels_of * up doc * up doc * add release tag placeholder * clean * up self config * up version
- Loading branch information
Showing
23 changed files
with
270 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace ArtARTs36\MergeRequestLinter\Application\Rule\Rules; | ||
|
||
use ArtARTs36\MergeRequestLinter\Application\Rule\Definition\Definition; | ||
use ArtARTs36\MergeRequestLinter\Domain\Request\MergeRequest; | ||
use ArtARTs36\MergeRequestLinter\Domain\Rule\RuleDefinition; | ||
use ArtARTs36\MergeRequestLinter\Shared\Attributes\Description; | ||
use ArtARTs36\Str\Facade\Str; | ||
use ArtARTs36\Str\Template\TemplatePlaceholders; | ||
|
||
#[Description('The description must match defined template. Available placeholders: {text}, {text_multiline}, {number}, {word}, {release_tag}')] | ||
final class DescriptionTemplateRule extends AbstractRule | ||
{ | ||
public const NAME = '@mr-linter/description_template'; | ||
private const TAG_PLACEHOLDER_REGEX = '(v?[0-9]+.[0-9]+.[0-9]+)(\-(\w+))?'; | ||
|
||
public function __construct( | ||
#[Description('Template for description')] | ||
private readonly string $template, | ||
#[Description('Custom definition')] | ||
private readonly ?string $definition = null, | ||
) { | ||
} | ||
|
||
protected function doLint(MergeRequest $request): bool | ||
{ | ||
return $request | ||
->descriptionMarkdown | ||
->str() | ||
->trim() | ||
->replace([ | ||
"\r\n" => "\n", | ||
]) | ||
->matchTemplate( | ||
Str::trim($this->template), | ||
TemplatePlaceholders::default() | ||
->add('release_tag', self::TAG_PLACEHOLDER_REGEX), | ||
) | ||
->matched; | ||
} | ||
|
||
public function getDefinition(): RuleDefinition | ||
{ | ||
return new Definition(sprintf( | ||
'Description template: %s', | ||
$this->definition ?? 'the description must match template', | ||
)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.