-
Notifications
You must be signed in to change notification settings - Fork 3
Fix mergYAMLNodes when the node is a sequence #128
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
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.
Hello @Nicogene, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request addresses issue #125 by fixing the mergeYAMLNodes
function to correctly handle merging YAML nodes when one of the nodes is a sequence. The original implementation only considered map types and would fail or produce incorrect results when encountering sequences. The updated function now includes logic to append items from the source sequence to the destination sequence if both nodes are sequences. Additionally, it handles cases where the destination and source are scalars or mismatched types by overwriting the destination with the source.
Highlights
- Bug Fix: Fixes a bug in
mergeYAMLNodes
where sequences were not handled correctly, resolving issue XMLBlobs seems to not be merged when using the include directive #125. - Sequence Handling: Implements logic to correctly merge YAML sequences by appending items from the source sequence to the destination sequence.
- Type Handling: Adds handling for scalar types and mismatched types, overwriting the destination node with the source node in these cases.
Changelog
- src/creo2urdf/src/Utils.cpp
- Added a check for null or invalid source nodes to prevent errors.
- Implemented logic to handle merging of YAML maps, iterating through the source map and merging each key-value pair into the destination map.
- Implemented logic to handle merging of YAML sequences, appending items from the source sequence to the destination sequence.
- Added logic to overwrite the destination node with the source node if they are scalars or of mismatched types.
- Line 272: Added a check for null or invalid source nodes to prevent errors.
- Line 275: Implemented logic to handle merging of YAML maps, iterating through the source map and merging each key-value pair into the destination map.
- Line 292: Implemented logic to handle merging of YAML sequences, appending items from the source sequence to the destination sequence.
- Line 299: Added logic to overwrite the destination node with the source node if they are scalars or of mismatched types.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A YAML node's deep merge,
Maps and sequences emerge,
From chaos to form,
Avoiding the storm,
Data's structure, we urge.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request addresses a bug in the mergeYAMLNodes
function, specifically when dealing with sequence nodes. The fix involves adding logic to handle sequence merging correctly, which is crucial for scenarios like merging XMLBlobs. The code is now more robust and handles different YAML node types effectively.
Summary of Findings
- Sequence Merging Logic: The added logic for merging sequence nodes by appending source items to the destination is a correct approach to fix the identified issue.
- Type Handling: The code now explicitly checks for map and sequence types before merging, and overwrites when types are mismatched or scalars are encountered, which provides more robust type handling.
- Null Check: The addition of a null check at the beginning of the function prevents potential errors when dealing with empty source nodes.
Merge Readiness
The code changes appear to correctly address the identified issue with merging YAML nodes, particularly sequences. The added checks for null values and different node types enhance the robustness of the function. I recommend merging this pull request after addressing the comments provided. I am unable to directly approve the pull request, and users should have others review and approve this code before merging.
else if (src.IsSequence() && dest.IsSequence()) { | ||
for (const auto& item : src) { | ||
dest.push_back(item); | ||
} |
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.
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.
It is too complex to do this check
// If dest and src are scalars or mismatched types, overwrite | ||
else { | ||
dest = src; | ||
} |
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.
This else
block overwrites the destination node if the types are mismatched or if they are scalars. While this behavior might be intended, it's worth documenting this explicitly with a comment to clarify the expected behavior for future maintainers.
// If dest and src are scalars or mismatched types, overwrite | |
else { | |
dest = src; | |
} | |
// If dest and src are scalars or mismatched types, overwrite | |
// This ensures that the destination node is updated with the source value | |
else { | |
dest = src; | |
} |
It fixes #125.
This function has been written by an old chatGPT and fixed by a newer chatGPT :D
Tested, it works now also with sequences (e.g. XMLBlobs)