Skip to content

Commit

Permalink
sort categories from new features, bugfixes and removed
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 19, 2025
1 parent c18a3c3 commit faf449d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/ChangelogContentsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public function create(array $changelogLines): string
Assert::allString($changelogLines);

// summarize into "Added Features" and "Bugfixes" groups
$linesByCategory = [];
$linesByCategory = [
// set order clearly here
ChangelogCategory::NEW_FEATURES => [],
ChangelogCategory::BUGFIXES => [],
ChangelogCategory::REMOVED => [],
ChangelogCategory::SKIPPED => [],
];

foreach ($changelogLines as $changelogLine) {
foreach (self::FILTER_KEYWORDS_BY_CATEGORY as $category => $filterKeywords) {
Expand All @@ -62,6 +68,9 @@ public function create(array $changelogLines): string
// remove skipped lines
unset($linesByCategory[ChangelogCategory::SKIPPED]);

// remove empty categories
$linesByCategory = array_filter($linesByCategory);

return $this->generateFileContentsFromGroupedItems($linesByCategory);
}

Expand Down Expand Up @@ -107,4 +116,26 @@ private function isKeywordsMatch(array $filterKeywords, string $changelogLine):

return false;
}

private function sortHeadlinesAsExpected(array $linesByCategory): array

Check failure on line 120 in src/ChangelogContentsFactory.php

View workflow job for this annotation

GitHub Actions / code_analysis_reusable / PHPStan

Method Rector\ReleaseNotesGenerator\ChangelogContentsFactory::sortHeadlinesAsExpected() has parameter $linesByCategory with no value type specified in iterable type array.

Check failure on line 120 in src/ChangelogContentsFactory.php

View workflow job for this annotation

GitHub Actions / code_analysis_reusable / PHPStan

Method Rector\ReleaseNotesGenerator\ChangelogContentsFactory::sortHeadlinesAsExpected() is unused.

Check failure on line 120 in src/ChangelogContentsFactory.php

View workflow job for this annotation

GitHub Actions / code_analysis_reusable / PHPStan

Method Rector\ReleaseNotesGenerator\ChangelogContentsFactory::sortHeadlinesAsExpected() return type has no value type specified in iterable type array.
{
// make sure the new features are first, bugfixes second and removed third
$newFeatures = $linesByCategory[ChangelogCategory::NEW_FEATURES] ?? [];
$bugfixes = $linesByCategory[ChangelogCategory::BUGFIXES] ?? [];
$removed = $linesByCategory[ChangelogCategory::REMOVED] ?? [];

$sortedLinesByCategory = [];
if ($newFeatures !== []) {
$sortedLinesByCategory[ChangelogCategory::NEW_FEATURES] = $newFeatures;
}

if ($bugfixes !== []) {
$sortedLinesByCategory[ChangelogCategory::BUGFIXES] = $bugfixes;
}

if ($removed !== []) {
$sortedLinesByCategory[ChangelogCategory::REMOVED] = $removed;
}
return $sortedLinesByCategory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ protected function setUp(): void
public function test(): void
{
$changelogLines = [
'* Add new rule',
'* Fix bug',
'* Add new rule',
'* Fixed another bug',
'* Removed old rule',
'* Enable PHPStan on tests as well + add "unused public" ([#3238](https://github.com/rectorphp/rector-src/pull/3238))',
];

Expand Down
6 changes: 6 additions & 0 deletions tests/ChangelogContentsFactory/Fixture/generated_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

* Fix bug
* Fixed another bug

<br>

## Removed :skull:

* Removed old rule

0 comments on commit faf449d

Please sign in to comment.