Skip to content

Commit 45b8b76

Browse files
committed
refactor: extract QA message logic
1 parent fbf1149 commit 45b8b76

File tree

1 file changed

+20
-18
lines changed
  • src/scripts/crowdin/translations

1 file changed

+20
-18
lines changed

src/scripts/crowdin/translations/utils.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ export const decompressFile = async (filePath: string, targetDir: string) => {
4040
console.log("✅ Decompression complete.")
4141
}
4242

43+
const getQAMessage = (locale: string) => {
44+
const summaryJson: QASummary = JSON.parse(readFileSync(SUMMARY_PATH, "utf-8"))
45+
const qaResults = summaryJson[locale]
46+
? summaryJson[locale].map((s) => "- " + s).join("\n")
47+
: null
48+
49+
if (!qaResults) return "No QA issues found"
50+
return `
51+
\`\`\`shell
52+
yarn markdown-checker
53+
\`\`\`l
54+
55+
<details><summary>Unfold for ${summaryJson[locale].length} result(s)</summary>
56+
57+
${qaResults}
58+
</details>
59+
`
60+
}
61+
4362
export const processLocale = (locale: string, buckets: number[]) => {
4463
const gitStatus = execSync(`git status -s | grep -E "/${locale}/" | wc -l`, {
4564
encoding: "utf-8",
@@ -61,11 +80,6 @@ export const processLocale = (locale: string, buckets: number[]) => {
6180
execSync(`git commit -m "${message}"`)
6281
execSync(`git push origin ${branchName}`)
6382

64-
const summaryJson: QASummary = JSON.parse(readFileSync(SUMMARY_PATH, "utf-8"))
65-
const qaResults = summaryJson[locale]
66-
? summaryJson[locale].map((s) => "- " + s).join("\n")
67-
: null
68-
6983
const prBody = `## Description
7084
This PR was automatically created to import Crowdin translations.
7185
This workflows runs on the first of every month at 16:20 (UTC).
@@ -78,20 +92,8 @@ export const processLocale = (locale: string, buckets: number[]) => {
7892
)}
7993
8094
## Markdown QA checker alerts
81-
${
82-
qaResults
83-
? `
84-
\`\`\`shell
85-
yarn markdown-checker
86-
\`\`\`l
87-
88-
<details><summary>Unfold for ${summaryJson[locale].length} result(s)</summary>
89-
90-
${qaResults}
91-
</details>
95+
${getQAMessage(locale)}
9296
`
93-
: "No QA issues found"
94-
}`
9597

9698
const bodyWritePath = path.resolve(process.cwd(), "body.txt")
9799
writeFileSync(bodyWritePath, prBody)

0 commit comments

Comments
 (0)