forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset-known-broken-translation-files.js
executable file
·55 lines (44 loc) · 1.48 KB
/
reset-known-broken-translation-files.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
require('dotenv').config()
const github = require('./helpers/github')()
const { promisify } = require('util')
const exec = promisify(require('child_process').exec)
// Check for required PAT
if (!process.env.GITHUB_TOKEN) {
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
process.exit(1)
}
// [start-readme]
//
// Use this script as part of the Crowdin merge process to get the list of known broken
// files and run script/reset-translated-file.js on them.
//
// [end-readme]
main()
async function main () {
// Get body text of OP from https://github.com/github/localization-support/issues/489.
const { data: { body } } = await github.issues.get({
owner: 'github',
repo: 'localization-support',
issue_number: '489'
})
// Get the list of broken files from the body text.
const brokenFiles = body
.replace(/^[\s\S]*?## List of Broken Translations/m, '')
.trim()
// Turn it into a simple array of files.
const brokenFilesArray = brokenFiles
.split('\n')
.map(line => line.replace('- [ ] ', '').trim())
// Run the script to revert them.
await Promise.all(brokenFilesArray.map(async (file) => {
console.log(`resetting ${file}`)
await exec(`script/reset-translated-file.js --prefer-main ${file}`)
}))
// Print a message with next steps.
console.log(`
Success!
Verify changes with git status and then run:
git commit --no-verify -m "Reset broken translated files to English"
`)
}