ACM-33139 Implement translation backporting mechanism#6099
ACM-33139 Implement translation backporting mechanism#6099jeswanke wants to merge 6 commits intostolostron:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jeswanke The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughAdds a TypeScript CLI (frontend/i18n-scripts/translation-backporting.ts) to backport translation changes between release refs, a tsconfig and ESLint override for the i18n-scripts directory, and package.json entries (script + devDependencies) to run the CLI. ChangesTranslation Backporting CLI
Sequence DiagramsequenceDiagram
participant User
participant CLI as i18n-backporting CLI
participant Git as Git (local/remote)
participant FS as Filesystem
participant GH as GitHub (gh)
User->>CLI: invoke (arg/env/interactive)
CLI->>Git: fetch upstream refs
CLI->>Git: git show <ref>:frontend/public/locales/*/translation.json
Git-->>CLI: translation file blobs
CLI->>CLI: compute diffs & getStringSimilarity
CLI->>User: prompt accept/backport? (TTY)
User-->>CLI: accept/reject
CLI->>FS: create temp worktree, write updated locale files
CLI->>Git: git add/commit/push branch
CLI->>GH: optionally gh pr create (target base)
GH-->>CLI: PR URL
CLI->>FS: remove worktree, cleanup
CLI-->>User: exit (summary/PR link)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
frontend/i18n-scripts/translation-backporting.ts (1)
6-7: 💤 Low valueDrop dead commented imports.
Proposed cleanup
import inquirer from 'inquirer' -// import readline from 'node:readline' -// import tty from 'node:tty' import { simpleGit, type SimpleGit } from 'simple-git'🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/i18n-scripts/translation-backporting.ts` around lines 6 - 7, Remove the dead commented import lines for "readline" and "tty" in translation-backporting.ts: delete the two commented lines "// import readline from 'node:readline'" and "// import tty from 'node:tty'" so the file contains only active imports and no stale commented code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/i18n-scripts/translation-backporting.ts`:
- Around line 590-602: The loop that builds translationMap currently assumes
git.show(spec) and JSON.parse(raw) always succeed, so a missing file or
malformed JSON at releaseRef will abort the whole backport; wrap the per-lang
retrieval inside a try/catch around git.show(spec) and JSON.parse(raw) (the code
referencing localeLangs, translationPath, git.show(spec), and
translationMap[lang]) and on error log a warning including lang and spec, then
either skip the lang or record a sentinel (e.g., null or an empty object) in
translationMap[lang] so the backport continues; ensure the catch distinguishes
missing-file vs parse errors in the message for easier debugging.
- Around line 303-305: The runCmd helper currently builds a single shell string
and calls execSync(cmd, { stdio:'inherit' }), which allows argument-boundary
breaks and shell-injection; change runCmd to accept a command plus an argv array
(or replace execSync with child_process.spawnSync/execFile using an args array)
and call execSync/execFile with { cwd, stdio:'inherit', encoding:'utf8',
shell:false } so arguments are not shell-interpolated. Update every call site
that passes interpolated branch names/refs/paths to pass the command and each
argument as separate entries (e.g. replace "git checkout -b ${branch}" with
["git","checkout","-b", branch]) and for places that relied on shell globbing
(frontend/public/locales/*) switch to adding the directory path (e.g.
"frontend/public/locales") or let git handle the path without shell expansion.
Ensure runCmd signature and all callers (the functions invoking runCmd) are
updated consistently.
- Around line 695-702: The prompt uses an unsupported type 'select' with
inquirer.prompt which will fail at runtime; change the prompt type to a
legacy-supported selection type such as 'list' (or 'rawlist') in the
inquirer.prompt call that builds releaseRef (the block that maps pickChoices via
pickChoices.map(({ name: ref, value: ref }))). Ensure the prompt remains
otherwise identical so releaseRef is returned as before.
- Around line 169-279: The code currently only writes to payloadMap when
currentRef === releaseRef (inside the orderedReleases loop) while
backportMap/backportEnMap accumulate across all iterations, causing the summary
(printBackportKeyCountsTable) to report more changes than are actually written;
choose the intended behavior and implement it: either (A) narrow the summary to
only count keys present in payloadMap before calling
printBackportKeyCountsTable, or (B) make payloadMap accumulate across the whole
loop by removing the currentRef === releaseRef guard and updating payloadMap
(and payloadChanged) whenever you add entries to backportEnMap/backportMap
(ensure you handle en separately via backportEnMap and similarity logic),
referencing the variables/functions payloadMap, payloadChanged, backportMap,
backportEnMap, currentRef, releaseRef, orderedReleases, and
printBackportKeyCountsTable so the counts and written disk payload stay in sync.
---
Nitpick comments:
In `@frontend/i18n-scripts/translation-backporting.ts`:
- Around line 6-7: Remove the dead commented import lines for "readline" and
"tty" in translation-backporting.ts: delete the two commented lines "// import
readline from 'node:readline'" and "// import tty from 'node:tty'" so the file
contains only active imports and no stale commented code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 10c7d47c-9163-4a00-8e40-fe74d49fd852
⛔ Files ignored due to path filters (1)
frontend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
frontend/eslint.config.mjsfrontend/i18n-scripts/translation-backporting.tsfrontend/i18n-scripts/tsconfig.jsonfrontend/package.json
Signed-off-by: John Swanke <jswanke@redhat.com>
📝 Summary
We're absolutely delighted to present the new frontend/i18n-scripts/translation-backporting.ts script
you can start it like this:
the first part of this script verifies or prompts for the release to backport
then list of all available releases before the target release is created:
'upstream/release-2.16' << target
'upstream/release-2.17'
'upstream/release-5.0' << latest
then starting with the target release:
a. use git to get the english translation.json for it and the next one down (2.17)
b. compare key/value pairs between 2.16 and 2.17
(1) if they are exactly the same, use this key to continue with the other languages:
(2) else check to see if they are similar--perhaps the english was simply polished
--to check if they are similar, use the getSimularity function to see how far apart they are:
in this example the strings are 0.97 similar (an s was added) so also use this key
upstream/release-2.16: The following disk will not be included in the snapshot
upstream/release-2.17: The following disks will not be included in the snapshot
similarity: 0.9725
in this example it's further apart--so user is prompted whether to use this key
upstream/release-2.16: Associated Placements or PlacementRules
upstream/release-2.17: Associated Placements
similarity: 0.6897
c. iterate thru languages using this key and when values don't match between 2.17 and 2.16, backport 2.17 to 2.16
create pr for the changesz:
a. create a worktree
b. create a new branch in worktree
c. use fs to copy the changes translation files into that worktree's branch
d. stage the changes
e. commit the changes
f. push the changes
g. use the github gh cli to create a pr
h. remove the worktree
Ticket Summary (Title):
ACM-33139 Implement translation backporting mechanism
Ticket Link:
https://redhat.atlassian.net/browse/ACM-33139
Type of Change:
✅ Checklist
General
ACM-12340 Fix bug with...)If Feature
If Bugfix
🗒️ Notes for Reviewers
Summary by CodeRabbit