* remove comments that no longer apply * remove unused matrix variables * remove CrowdIn-specific step of resetting broken files * udpate link to Microsoft-specific log * bring back reset script still in use * add acceptable ja translation of TOS to rendering test * add ability to remove files that have been translated but don't exist (wip) * document what `languageFiles()` returns * fix path issues for removed translations * cleaner script execution * add removed files to CSV report * add workflow link to PR body for better troubleshooting * catch missing regex for reporting file removals * fix capturing groups in regex for csv reporting * fix link to CSV file for PR * fix formatting for PR * pass in branch name from workflow * put back helper scripts, make msft-specific copies
70 lines
2.0 KiB
JavaScript
Executable File
70 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import { program } from 'commander'
|
|
import fs from 'fs'
|
|
import languages from '../../lib/languages.js'
|
|
|
|
const defaultWorkflowUrl = [
|
|
process.env.GITHUB_SERVER_URL,
|
|
process.env.GITHUB_REPOSITORY,
|
|
'actions/runs',
|
|
process.env.GITHUB_RUN_ID,
|
|
].join('/')
|
|
|
|
const reportTypes = {
|
|
'pull-request-body': pullRequestBodyReport,
|
|
csv: csvReport,
|
|
}
|
|
|
|
program
|
|
.description('Reads a translation batch log and generates a report')
|
|
.requiredOption('--language <language>', 'The language to compare')
|
|
.requiredOption('--log-file <log-file>', 'The batch log file')
|
|
.requiredOption(
|
|
'--report-type <report-type>',
|
|
'The batch log file, I.E: ' + Object.keys(reportTypes).join(', ')
|
|
)
|
|
.option('--workflow-url <workflow-url>', 'The workflow url', defaultWorkflowUrl)
|
|
.option('--csv-path <file-path>', 'The path to the CSV file')
|
|
.parse(process.argv)
|
|
|
|
const options = program.opts()
|
|
const language = languages[options.language]
|
|
const { logFile, workflowUrl, reportType, csvPath } = options
|
|
|
|
if (!Object.keys(reportTypes).includes(reportType)) {
|
|
throw new Error(`Invalid report type: ${reportType}`)
|
|
}
|
|
|
|
const logFileContents = fs.readFileSync(logFile, 'utf8')
|
|
|
|
const revertLines = logFileContents
|
|
.split('\n')
|
|
.filter((line) => line.match(/^(-> reverted to English)|^(-> removed)/))
|
|
.filter((line) => line.match(language.dir))
|
|
|
|
const reportEntries = revertLines.sort().map((line) => {
|
|
const [, file, reason] = line.match(/^-> (?:reverted to English|removed): (.*) Reason: (.*)$/)
|
|
return { file, reason }
|
|
})
|
|
|
|
function pullRequestBodyReport() {
|
|
return [
|
|
`New translation batch for ${language.name}. Product of [this workflow](${workflowUrl}).
|
|
|
|
## ${reportEntries.length} files reverted.
|
|
|
|
You can see the log in [\`${csvPath}\`](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/blob/${csvPath}).`,
|
|
].join('\n')
|
|
}
|
|
|
|
function csvReport() {
|
|
const lines = reportEntries.map(({ file, reason }) => {
|
|
return [file, reason].join(',')
|
|
})
|
|
|
|
return ['file,reason', lines].flat().join('\n')
|
|
}
|
|
|
|
console.log(reportTypes[reportType]())
|