-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmessage-formatter.ts
More file actions
25 lines (20 loc) · 733 Bytes
/
message-formatter.ts
File metadata and controls
25 lines (20 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { EOL } from 'node:os';
import { type Author } from '../author';
export enum AuthorTrailers {
CoAuthorBy = 'Co-authored-by',
SignedOffBy = 'Signed-off-by',
ReviewedBy = 'Reviewed-by',
}
function removeTrailers(txt: string): string {
const trailers = Object.values(AuthorTrailers).join('|');
const regex = new RegExp(`(\r\n|\r|\n){0,2}(${trailers}).*`, 'g');
return txt.replaceAll(regex, '');
}
export function messageFormatter(txt: string, authors: Author[]): string {
const message = removeTrailers(txt);
if (authors && authors.length > 0) {
const authorTrailerTxt = authors.map(author => author.format()).join(EOL);
return [message, EOL, EOL, authorTrailerTxt].join('');
}
return message;
}