-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor metadata PO files generation #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
Generated by 🚫 Danger |
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename `po` parameter to `po_data` (min 3 chars) - Fix context description wording in spec Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9e9b07e to
2dc9458
Compare
2dc9458 to
fc65181
Compare
AliSoftware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only skimmed the diff so far (so not a deep dive review, and also haven't tested it at all) so this is only a first-pass review. Still promising though!
| @current_block = block if block.is_handler_for(key) | ||
| end | ||
| def self.commit_changes(params) | ||
| Action.sh("git add #{params[:po_file_path]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid shelling out to do git operations
- First and most importantly, calling
sh("git add #{file}")is unsafe and a security risk (think paths with spaces, accidental extra shell interpolation, injection …). If we still wanted to shell out to call git at the very least we should call this assh('git', 'add', file)(instead ofsh("git add #{file}")) to avoid the extra layer of having the shell parsing and interpreting the string as a command and separate arguments but instead pass the separate arguments from the get go - But also, there are already some fastlane actions that exist to handle
git_addand similar, so would probably make more sense to use them - Or alternatively use one of our git helpers for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point -- this code was moved from the iOS action while consolidating iOS and Android into it and ended up unchanged. Updated to use Fastlane actions on 4b92f8f.
| repo_status = Actions.sh('git status --porcelain') | ||
| repo_clean = repo_status.empty? | ||
| return if repo_clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, we should call the existing ensure_git_repo_clean action (or whatever it's called) here instead of reinventing the wheel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated on 4b92f8f.
| # Preserve header from existing PO file if available | ||
| add_header(po) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's worth for the helper (and the action that calls it) to need to read / rely on the existing po file anymore (after all the whole point of this new approach is to not have to rely on an existing po to begin with)
Instead I'd recommend to remove the @existing_po_path attribute from this helper entirely, and instead hardcode the typical header fields and values we want to include in the PO files generated from scratch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also went back and forth with this but I agree: aside from making the PO file structure more predictable, not worrying about a previously existing file simplifies the code a lot. Updated on cede46f.
Code Review: PR #684 - Refactor metadata PO files generationI'll provide a comprehensive review of this pull request, analyzing the refactoring, implementation quality, and potential concerns.
🎯 Overall Assessment: STRONG REFACTOR ✅This is a well-executed refactoring that significantly improves code maintainability. The PR demonstrates good engineering practices with comprehensive tests, clear migration documentation, and thoughtful API design. ✅ Strengths1. Architecture Improvements
2. API Design# Clean support for both simple and complex formats
source_files: {
app_name: 'path/to/name.txt', # Simple
app_store_subtitle: { # With translator comment
path: 'path/to/subtitle.txt',
comment: 'translators: Limit to 30 characters!'
}
}This is elegant backward-compatible design. 3. Test CoverageThe new
4. Documentation
|
1. Removed `ensure_git_status_clean` from `gp_update_metadata_source.rb` 2. Added `:path` key validation in `extract_path_and_comment` 3. Added proper error handling to `parse_version` 4. Empty `whats_new` content handling 5. DRYed up versioned key methods 6. Added a few new tests.
Nice one! The first point:
This doesn't really apply as the idea is to overwrite the file and the check is just to be sure there's nothing else in progress.
Interesting, this point is wrong (aside from the weird line reference? Perhaps it's the line number from the diff?). Both iOS and Android are almost identical. Perhaps it got confused with the diff? 🤔 About other recommendations, I've implemented:
Updated on 073d704. |
Fixes AINFRA-1724
See discussion on Slack: p1767962906955309-slack-CC7L49W13
See test PR: woocommerce/woocommerce-ios#16502
Summary
The main goal of this PR is to fix the issue when generating the .po / .pot files where new entries aren't present in the output or removed entries are removed. To do that, I've consolidated the metadata PO file generation into a new
PoFileGeneratorclass using gettext. Theios_update_metadata_sourceandan_update_metadata_sourceactions are now deprecated and delegate togp_update_metadata_source.What's Changed
New Features:
source_filesnow accepts{ path: 'file.txt', comment: 'translators: ...' }formatcommit_changesoption: Auto-commit support ongp_update_metadata_sourceOutput Changes:
msgctxtfor deterministic output#.lines) must now be explicitly provided—they're no longer preserved from existing PO filesPO-Revision-Dateis now updated with the current date timeBreaking Changes
Migration
When upgrading, callers need to copy comments from
.po/.potfiles to thegp_update_metadata_sourcecall site in theFastfileto make sure the comments remain in the generated file. SeeMIGRATION.mdfor details.Deprecations
ios_update_metadata_sourcegp_update_metadata_sourcewithcommit_changes: truean_update_metadata_sourcegp_update_metadata_sourceDeprecated actions still work (API unchanged) but the output will be different (the comments and header will be removed and the keys will be sorted alphabetically, mainly).