From 74e4df1a55b3159fc9a5450981d51b01e310e2eb Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 19 Jan 2025 11:08:03 +0000 Subject: [PATCH] Sort categories from: new features, bugfixes and removed (#4) * cz * sort categories from new features, bugfixes and removed --- LICENSE | 2 +- src/ChangelogContentsFactory.php | 11 ++++++++++- .../ChangelogContentsFactoryTest.php | 3 ++- .../Fixture/generated_changelog.md | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index a89e419..67b0a78 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License --------------- -Copyright (c) 2017-present Tomáš Votruba (https://tomasvotruba.cz) +Copyright (c) 2017-present Tomáš Votruba (https://tomasvotruba.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/src/ChangelogContentsFactory.php b/src/ChangelogContentsFactory.php index e3db8be..33650fb 100644 --- a/src/ChangelogContentsFactory.php +++ b/src/ChangelogContentsFactory.php @@ -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) { @@ -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); } diff --git a/tests/ChangelogContentsFactory/ChangelogContentsFactoryTest.php b/tests/ChangelogContentsFactory/ChangelogContentsFactoryTest.php index 0222419..38d93a7 100644 --- a/tests/ChangelogContentsFactory/ChangelogContentsFactoryTest.php +++ b/tests/ChangelogContentsFactory/ChangelogContentsFactoryTest.php @@ -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))', ]; diff --git a/tests/ChangelogContentsFactory/Fixture/generated_changelog.md b/tests/ChangelogContentsFactory/Fixture/generated_changelog.md index aa58ef7..4cc134d 100644 --- a/tests/ChangelogContentsFactory/Fixture/generated_changelog.md +++ b/tests/ChangelogContentsFactory/Fixture/generated_changelog.md @@ -8,3 +8,9 @@ * Fix bug * Fixed another bug + +
+ +## Removed :skull: + +* Removed old rule