@@ -43,7 +43,13 @@ public function create(array $changelogLines): string
43
43
Assert::allString ($ changelogLines );
44
44
45
45
// 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
+ ];
47
53
48
54
foreach ($ changelogLines as $ changelogLine ) {
49
55
foreach (self ::FILTER_KEYWORDS_BY_CATEGORY as $ category => $ filterKeywords ) {
@@ -62,6 +68,9 @@ public function create(array $changelogLines): string
62
68
// remove skipped lines
63
69
unset($ linesByCategory [ChangelogCategory::SKIPPED ]);
64
70
71
+ // remove empty categories
72
+ $ linesByCategory = array_filter ($ linesByCategory );
73
+
65
74
return $ this ->generateFileContentsFromGroupedItems ($ linesByCategory );
66
75
}
67
76
@@ -107,4 +116,26 @@ private function isKeywordsMatch(array $filterKeywords, string $changelogLine):
107
116
108
117
return false ;
109
118
}
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
+ }
110
141
}
0 commit comments