@@ -6,10 +6,13 @@ class CommitFormatter {
66 private array $ commitsList = [];
77
88 private array $ commitsGroupedByAuthor = [];
9+
10+ private array $ nameReplacements = [];
911 private const EOL = "\r\n" ;
1012
11- public function __construct (array $ inputCommits ) {
13+ public function __construct (array $ inputCommits, array $ nameReplacements = [] ) {
1214 $ this ->process ($ inputCommits );
15+ $ this ->nameReplacements = $ nameReplacements ;
1316 }
1417
1518 private function process (array $ inputCommits ): void {
@@ -35,7 +38,15 @@ private function process(array $inputCommits): void {
3538 }
3639
3740 $ this ->commitsList = $ formattedCommits ;
38- ksort ($ this ->commitsGroupedByAuthor );
41+
42+ foreach ($ this ->nameReplacements as $ originalName => $ newName ) {
43+ if (isset ($ this ->commitsGroupedByAuthor [$ originalName ])) {
44+ $ this ->commitsGroupedByAuthor [$ newName ] = $ this ->commitsGroupedByAuthor [$ originalName ];
45+ unset($ this ->commitsGroupedByAuthor [$ originalName ]);
46+ }
47+ }
48+
49+ ksort ($ this ->commitsGroupedByAuthor , SORT_NATURAL | SORT_FLAG_CASE );
3950 }
4051
4152 private function splitCommit (\stdClass $ commit ): array {
@@ -88,7 +99,7 @@ public function getFormattedCommitList(): array {
8899 public function getFormattedCommitListMarkup (): string {
89100 $ output = '' ;
90101 foreach ($ this ->getFormattedCommitList () as $ commit ) {
91- $ output .= $ this -> getFormattedCommitListMarkup ($ commit ['formatted ' ] . ' by ' . $ commit ['author ' ]);
102+ $ output .= self :: markdownListItem ($ commit ['formatted ' ] . ' by ' . ( $ this -> nameReplacements [ $ commit ['author ' ]] ?? $ commit [ ' author ' ]) );
92103 }
93104
94105 return $ output ;
@@ -114,6 +125,8 @@ public function getFormattedCommitListGroupedByAuthorMarkup(): string {
114125 foreach ($ commitList as $ commit ) {
115126 $ output .= self ::markdownListItem ($ commit ['formatted ' ]);
116127 }
128+
129+ $ output .= self ::EOL . self ::EOL ;
117130 }
118131
119132 return $ output ;
0 commit comments