Skip to content

Commit 0cc4177

Browse files
committed
feat: update changelog format to use brackets for unreleased entries and improve dependency initialization in commands
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 4948ade commit 0cc4177

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/Changelog/UnreleasedEntryChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function hasPendingChanges(string $workingDirectory, ?string $againstRefe
9494
*/
9595
private function extractEntries(string $contents): array
9696
{
97-
if (0 === preg_match('/^## Unreleased\s+-\s+.+?(?=^##\s|\z)/ms', $contents, $matches)) {
97+
if (0 === preg_match('/^## \[?Unreleased\]?\s+-\s+.+?(?=^##\s|\z)/ms', $contents, $matches)) {
9898
return [];
9999
}
100100

src/Command/ChangelogCheckCommand.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
final class ChangelogCheckCommand extends AbstractCommand
3232
{
3333
/**
34-
* @param Filesystem|null $filesystem
35-
* @param UnreleasedEntryCheckerInterface|null $unreleasedEntryChecker
34+
* Initializes the command with necessary dependencies.
35+
*
36+
* @param Filesystem $filesystem filesystem instance for file operations
37+
* @param UnreleasedEntryCheckerInterface $unreleasedEntryChecker checker for pending unreleased entries in the changelog
3638
*/
3739
public function __construct(
38-
?Filesystem $filesystem = null,
39-
private readonly ?UnreleasedEntryCheckerInterface $unreleasedEntryChecker = null,
40+
Filesystem $filesystem = new Filesystem(),
41+
private readonly UnreleasedEntryCheckerInterface $unreleasedEntryChecker = new UnreleasedEntryChecker(),
4042
) {
4143
parent::__construct($filesystem);
4244
}
@@ -60,14 +62,16 @@ protected function configure(): void
6062
}
6163

6264
/**
63-
* @param InputInterface $input
64-
* @param OutputInterface $output
65+
* Executes the command to check for pending unreleased changes in the changelog.
66+
*
67+
* @param InputInterface $input the input interface for command arguments and options
68+
* @param OutputInterface $output the output interface for writing command output
6569
*
66-
* @return int
70+
* @return int exit code indicating success (0) or failure (1)
6771
*/
6872
protected function execute(InputInterface $input, OutputInterface $output): int
6973
{
70-
$hasPendingChanges = ($this->unreleasedEntryChecker ?? new UnreleasedEntryChecker())
74+
$hasPendingChanges = $this->unreleasedEntryChecker
7175
->hasPendingChanges($this->getCurrentWorkingDirectory(), $input->getOption('against'));
7276

7377
if ($hasPendingChanges) {

tests/Composer/Capability/DevToolsCommandProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use FastForward\DevTools\Command\SyncCommand;
3131
use FastForward\DevTools\Command\SkillsCommand;
3232
use FastForward\DevTools\Agent\Skills\SkillsSynchronizer;
33+
use FastForward\DevTools\Changelog\UnreleasedEntryChecker;
3334
use FastForward\DevTools\Command\PhpDocCommand;
3435
use FastForward\DevTools\Command\RefactorCommand;
3536
use FastForward\DevTools\Command\ReportsCommand;
@@ -76,6 +77,7 @@
7677
#[UsesClass(GitAttributesWriter::class)]
7778
#[UsesClass(GitIgnoreMerger::class)]
7879
#[UsesClass(Writer::class)]
80+
#[UsesClass(UnreleasedEntryChecker::class)]
7981
final class DevToolsCommandProviderTest extends TestCase
8082
{
8183
private DevToolsCommandProvider $commandProvider;

0 commit comments

Comments
 (0)