Skip to content

Commit faf449d

Browse files
committed
sort categories from new features, bugfixes and removed
1 parent c18a3c3 commit faf449d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

Diff for: src/ChangelogContentsFactory.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public function create(array $changelogLines): string
4343
Assert::allString($changelogLines);
4444

4545
// summarize into "Added Features" and "Bugfixes" groups
46-
$linesByCategory = [];
46+
$linesByCategory = [
47+
// set order clearly here
48+
ChangelogCategory::NEW_FEATURES => [],
49+
ChangelogCategory::BUGFIXES => [],
50+
ChangelogCategory::REMOVED => [],
51+
ChangelogCategory::SKIPPED => [],
52+
];
4753

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

71+
// remove empty categories
72+
$linesByCategory = array_filter($linesByCategory);
73+
6574
return $this->generateFileContentsFromGroupedItems($linesByCategory);
6675
}
6776

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

108117
return false;
109118
}
119+
120+
private function sortHeadlinesAsExpected(array $linesByCategory): array
121+
{
122+
// make sure the new features are first, bugfixes second and removed third
123+
$newFeatures = $linesByCategory[ChangelogCategory::NEW_FEATURES] ?? [];
124+
$bugfixes = $linesByCategory[ChangelogCategory::BUGFIXES] ?? [];
125+
$removed = $linesByCategory[ChangelogCategory::REMOVED] ?? [];
126+
127+
$sortedLinesByCategory = [];
128+
if ($newFeatures !== []) {
129+
$sortedLinesByCategory[ChangelogCategory::NEW_FEATURES] = $newFeatures;
130+
}
131+
132+
if ($bugfixes !== []) {
133+
$sortedLinesByCategory[ChangelogCategory::BUGFIXES] = $bugfixes;
134+
}
135+
136+
if ($removed !== []) {
137+
$sortedLinesByCategory[ChangelogCategory::REMOVED] = $removed;
138+
}
139+
return $sortedLinesByCategory;
140+
}
110141
}

Diff for: tests/ChangelogContentsFactory/ChangelogContentsFactoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ protected function setUp(): void
1919
public function test(): void
2020
{
2121
$changelogLines = [
22-
'* Add new rule',
2322
'* Fix bug',
23+
'* Add new rule',
2424
'* Fixed another bug',
25+
'* Removed old rule',
2526
'* Enable PHPStan on tests as well + add "unused public" ([#3238](https://github.com/rectorphp/rector-src/pull/3238))',
2627
];
2728

Diff for: tests/ChangelogContentsFactory/Fixture/generated_changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88

99
* Fix bug
1010
* Fixed another bug
11+
12+
<br>
13+
14+
## Removed :skull:
15+
16+
* Removed old rule

0 commit comments

Comments
 (0)