-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support <lang> pattern in path instead of file name #8
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
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe PR refactors the target file discovery to branch on whether the Class diagram for Filter::find_target_files method updateclassDiagram
class Filter {
+find_target_files(target_pattern_path: &Path) -> Result<Vec<(String, PathBuf)>>
}
Filter : +find_target_files now supports <lang> in path
Filter : +find_target_files branches on <lang> in file name vs path
Flow diagram for target file discovery with in file name vs pathflowchart TD
A[Start: target_filename_pattern] --> B{Does target_filename_pattern contain <lang>?}
B -- Yes --> C[Use regex filter on file names in parent directory]
C --> D[Collect matched files with language code]
B -- No --> E[Parse path components to find <lang>]
E --> F{Is <lang> found in path?}
F -- No --> G[Return error: Missing <lang> in pattern]
F -- Yes --> H[Iterate subdirectories in parent_dir]
H --> I[Validate subdirectory as language code]
I --> J[Check if file exists in subdirectory]
J --> K[Collect matched files with language code]
D & K --> L[Return matched files]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @BLumia - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/transifex/yaml_file.rs:132` </location>
<code_context>
+ parent_dir.push(component);
+ }
+ };
+ if remain_path == None {
+ return Err(std::io::Error::new(std::io::ErrorKind::Other, "Missing <lang> inside the pattern."));
+ }
</code_context>
<issue_to_address>
Consider using `is_none()` instead of `== None` for Option checks.
This change aligns with Rust idioms and prevents clippy warnings.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if remain_path == None {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Missing <lang> inside the pattern."));
}
=======
if remain_path.is_none() {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Missing <lang> inside the pattern."));
}
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `src/transifex/yaml_file.rs:145` </location>
<code_context>
+ let Some(language_folder) = language_folder.to_str() else {
+ continue;
+ };
+ if !regex::Regex::new(r"[a-z_A-Z]{2,6}").unwrap().is_match(language_folder) {
+ continue;
+ }
</code_context>
<issue_to_address>
Regex is compiled on every iteration, which is inefficient.
Compile the regex once before the loop and reuse it to improve performance.
</issue_to_address>
### Comment 3
<location> `src/transifex/yaml_file.rs:148` </location>
<code_context>
+ if !regex::Regex::new(r"[a-z_A-Z]{2,6}").unwrap().is_match(language_folder) {
+ continue;
+ }
+ let matched_file = language_folder_dir.join(remain_path.clone().unwrap());
+ if !matched_file.is_file() {
+ continue;
</code_context>
<issue_to_address>
Repeatedly calling `clone().unwrap()` on `remain_path` can be avoided.
Unwrap `remain_path` once before the loop and reuse the value to avoid unnecessary cloning and unwrapping in each iteration.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This is mainly for gettext support. Log:
deepin pr auto review代码审查意见:
|
This is mainly for gettext support.
Log:
Summary by Sourcery
Add support for
<lang>placeholder in pattern paths to resolve language-specific files by filename or directory structureNew Features:
<lang>in target filenames to match and capture language codes from filenames in a directory<lang>in path segments to match language code subdirectories and locate corresponding files