diff --git a/tools/get-change-log-for-release.js b/tools/get-change-log-for-release.js index bf941b9395e..5462299e20e 100644 --- a/tools/get-change-log-for-release.js +++ b/tools/get-change-log-for-release.js @@ -11,9 +11,10 @@ const main = async () => { validateCommandLineArguments(params); const gitLogs = await getGitLogs(params.from, params.to); - - const outputContent = generateOutputContent(gitLogs, params.to); - + const outputContent = + params.kind === 'csv' + ? generateCSVContent(gitLogs, params.to) + : generateTextContent(gitLogs); ensureOutputFileExist(params.output); fs.writeFileSync(params.output, outputContent); @@ -62,14 +63,45 @@ const makePrLink = pr => { return pr; } - return `=HYPERLINK("https://github.com/microsoft/accessibility-insights-web/pull/${pr}", "#${pr}")`; + return `=HYPERLINK("${makePrURL(pr)}", "#${pr}")`; +}; + +const makePrURL = pr => { + return `https://github.com/microsoft/accessibility-insights-web/pull/${pr}`; }; const makeCommitLink = commit => { - return `=HYPERLINK("https://github.com/microsoft/accessibility-insights-web/commit/${commit}", "${commit}")`; + return `=HYPERLINK("${makeCommitURL(commit)}", "${commit}")`; +}; + +const makeCommitURL = commit => { + return `https://github.com/microsoft/accessibility-insights-web/commit/${commit}`; }; -const generateOutputContent = (gitLogs, version) => { +const generateTextContent = gitLogs => { + let outputText = ''; + gitLogs.all + .map(log => { + return { + dev: log.author_name, + pr: makePrURL(extractPrNumber(log.message)), + change: log.message, + group: getCommitType(log.message), + }; + }) + .filter(log => { + return ( + !['chore(deps-dev)'].includes(log.group) && !['dependabot[bot]'].includes(log.dev) + ); + }) + .sort((a, b) => a.group - b.group) + .forEach(log => { + outputText += `[tester]\n\tdev: ${log.dev}\n\tpr: ${log.pr}\n\tgroup: ${log.group}\n\tchange: ${log.change}\n`; + }); + return outputText; +}; + +const generateCSVContent = (gitLogs, version) => { const csvLogs = gitLogs.all .map(log => { return { @@ -107,6 +139,11 @@ const parseCommandLineArguments = () => { '-o, --output ', 'Path to the output file. Default: change-log.-.csv', ) + .option( + '-k, --kind ', + 'Type of desired output, csv or txt. Default: csv', + 'csv', + ) .parse(process.argv); return program.opts(); @@ -114,7 +151,6 @@ const parseCommandLineArguments = () => { const validateCommandLineArguments = program => { const errors = []; - if (!program.from) { errors.push('Missing param: from'); } @@ -123,8 +159,12 @@ const validateCommandLineArguments = program => { errors.push('Missing param: to'); } + if (!program.kind) { + program.kind = 'csv'; + } + if (!program.output) { - program.output = `change-log.${program.from}-${program.to}.csv`; + program.output = `change-log.${program.from}-${program.to}.${program.kind}`; } if (errors.length !== 0) {