[AAE-11708] Fix changelog author filtering programatically (#8178)

This commit is contained in:
Pablo Martinez Garcia
2023-01-26 17:23:23 +01:00
committed by GitHub
parent 42dbfe25ac
commit 4a3bc568ad

View File

@@ -78,11 +78,11 @@ function getRemote(workingDir: string): string {
function getCommits(options: DiffOptions): Array<Commit> { function getCommits(options: DiffOptions): Array<Commit> {
let authorFilter = (options.exclude || '') let authorFilter = (options.exclude || '')
.split(',') .split(',')
.map(str => str.trim()) .map(str => str.trim().replace(/\\/g, ''))
.join('\|'); .join('|');
if (!authorFilter) { if (!authorFilter) {
authorFilter = `bot\|Alfresco Build User`; authorFilter = `bot|Alfresco Build User`;
} }
@@ -92,8 +92,6 @@ function getCommits(options: DiffOptions): Array<Commit> {
options.range, options.range,
`--no-merges`, `--no-merges`,
`--first-parent`, `--first-parent`,
`--perl-regexp`,
`--author="^((?!${authorFilter}).*)$"`,
// this format is needed to allow parsing all characters in the commit message and safely convert to JSON // this format is needed to allow parsing all characters in the commit message and safely convert to JSON
`--format="{ ^@^hash^@^: ^@^%h^@^, ^@^author^@^: ^@^%an^@^, ^@^author_email^@^: ^@^%ae^@^, ^@^date^@^: ^@^%ad^@^, ^@^subject^@^: ^@^%s^@^ }"` `--format="{ ^@^hash^@^: ^@^%h^@^, ^@^author^@^: ^@^%an^@^, ^@^author_email^@^: ^@^%ae^@^, ^@^date^@^: ^@^%ad^@^, ^@^subject^@^: ^@^%s^@^ }"`
]; ];
@@ -116,7 +114,12 @@ function getCommits(options: DiffOptions): Array<Commit> {
log = log.substring(0, log.length - 1); log = log.substring(0, log.length - 1);
} }
return log.split('\n').map(str => JSON.parse(str) as Commit); return log.split('\n').map(str => JSON.parse(str) as Commit).filter(commit => commitAuthorAllowed(commit, authorFilter));
}
function commitAuthorAllowed(commit: Commit, authorFilter: string): boolean {
const filterRegex = RegExp(authorFilter);
return !(filterRegex.test(commit.author) || filterRegex.test(commit.author_email));
} }
export default function main(_args: string[], workingDir: string) { export default function main(_args: string[], workingDir: string) {
@@ -124,7 +127,7 @@ export default function main(_args: string[], workingDir: string) {
.description('Generate changelog report for two branches of git repository') .description('Generate changelog report for two branches of git repository')
.version('0.0.1', '-v, --version') .version('0.0.1', '-v, --version')
.usage('changelog [options]') .usage('changelog [options]')
.option('-r, --range <range>', 'Commit range, e.g. master..develop', 'master..develop') .option('-r, --range <range>', 'Commit range, e.g. origin/master..develop', 'origin/qmaster..develop')
.option('-d, --dir <dir>', 'Working directory (default: working directory)') .option('-d, --dir <dir>', 'Working directory (default: working directory)')
.option('-m, --max <number>', 'Limit the number of commits to output') .option('-m, --max <number>', 'Limit the number of commits to output')
.option('-o, --output <dir>', 'Output directory, will use console output if not defined') .option('-o, --output <dir>', 'Output directory, will use console output if not defined')