generated from Adiltonzs/docs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-crowdin-issue.js
executable file
·121 lines (94 loc) · 2.8 KB
/
update-crowdin-issue.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env node
// [start-readme]
//
// Use this script as the last step of the Crowdin merge process to:
// 1. Add newly found broken translated files to the localization-support issue OP.
// 2. Add a comment on the issue with more details.
//
// [end-readme]
import dotenv from 'dotenv'
import Github from './helpers/github.js'
import { execSync } from 'child_process'
dotenv.config()
const github = Github()
// 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)
}
const fixableErrorsLog = '~/docs-translation-errors-fixable.txt'
const parsingErrorsLog = '~/docs-translation-parsing-error.txt'
const renderingErrorsLog = '~/docs-translation-rendering-error.txt'
// Get just the fixable files:
const fixable = execSync(
`cat ${fixableErrorsLog} | egrep "^translations/.*/(.+.md|.+.yml)$" | sed -e 's/^/- [ ] /' | uniq`
).toString()
// Get a list of files to be added to the body of the issue
const filesToAdd = execSync(
`cat ${parsingErrorsLog} ${renderingErrorsLog} | egrep "^translations/.*/(.+.md|.+.yml)$" | sed -e 's/^/- [ ] /' | uniq`
).toString()
// Cat the three error logs together
const allErrors = execSync('cat ~/docs-*').toString()
const comment = `
Did a fresh merge today!
<details>
<summary>In addition to the files in the PR body, these files also have errors, but can be fixed programmatically:</summary>
${fixable}
</details>
<details>
<summary>Here are the <b>new</b> errors:</summary>
\`\`\`
${allErrors}
\`\`\`
</details>
`
const owner = 'github'
const repo = 'localization-support'
const issueNumber = '489'
main()
async function main() {
await updateIssueBody()
await addNewComment()
console.log('Success! You can safely delete the temporary logfiles under ~/docs-*.')
}
async function updateIssueBody() {
// Get current body text of OP from https://github.com/github/localization-support/issues/489.
const {
data: { body },
} = await github.issues.get({
owner,
repo,
issue_number: issueNumber,
})
// Update the body with the list of newly broken files
const newBody = body + '\n' + filesToAdd
// Update the issue
try {
await github.issues.update({
owner,
repo,
issue_number: issueNumber,
body: newBody,
})
console.log(
'Added newly found broken files to OP of https://github.com/github/localization-support/issues/489!\n'
)
} catch (err) {
console.error(err)
}
}
async function addNewComment() {
try {
await github.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: comment,
})
console.log(
'Added comment to the end of https://github.com/github/localization-support/issues/489!\n'
)
} catch (err) {
console.error(err)
}
}