Skip to content

chore: add handling for converting newlines in documentoverrides from toml to yaml#3284

Merged
ldetmer merged 1 commit intomainfrom
newline-fix
Dec 18, 2025
Merged

chore: add handling for converting newlines in documentoverrides from toml to yaml#3284
ldetmer merged 1 commit intomainfrom
newline-fix

Conversation

@ldetmer
Copy link
Copy Markdown
Contributor

@ldetmer ldetmer commented Dec 17, 2025

Newlines were getting stripped from documentoverrides field. Originally I had tried the "proper" solution to set this field to LiteralStyle in yaml which should then keep the newlines. However that was not working properly when we read and wrote back to the file.. Since this is a 1 time migration script I decided just to go with a brute force solution to unblock us as this code will not be used once we migrate the sidekick repo.

Fix #3136

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ldetmer, 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!

This pull request introduces a crucial fix for the migrate-sidekick tool, specifically addressing how newlines are handled when converting rust.DocumentationOverrides from TOML to YAML. The changes ensure that multi-line match and replace values are correctly formatted in the resulting YAML configuration, preventing data corruption and maintaining the intended structure of documentation overrides.

Highlights

  • Newline Handling for Documentation Overrides: Implemented a new function fixDocumentOverrideNewLines to correctly convert multi-line match and replace fields within rust.DocumentationOverrides from TOML to YAML, ensuring proper formatting.
  • New Data Structure: Introduced RustOverrideData to facilitate the processing and lookup of documentation override data during the conversion.
  • Integration into Migration Flow: The run function now invokes fixDocumentOverrideNewLines to apply the necessary newline fixes after the initial migration process, ensuring the generated YAML is correctly formatted.
  • Enhanced Testing: Added a new test case in TestRunMigrateCommand to verify the accurate handling of multi-line documentation overrides, including specific assertions for the replace field's content after conversion.
  • Updated Test Data: Modified a test TOML file (.sidekick.toml) to include an example of multi-line documentation-overrides for comprehensive testing of the new newline handling logic.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

Footnotes

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a post-processing step to the sidekick migration tool to handle newlines in documentoverrides when converting from TOML to YAML. While the intent is correct, the implementation manually parses the YAML file using string manipulation, which is highly fragile and prone to breaking. My review includes a critical comment suggesting a refactor to use the YAML library's AST manipulation features for a more robust and maintainable solution.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 78.84615% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.29%. Comparing base (f11bb69) to head (32994d1).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
devtools/cmd/migrate-sidekick/main.go 78.84% 6 Missing and 5 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3284   +/-   ##
=======================================
  Coverage   80.28%   80.29%           
=======================================
  Files         162      162           
  Lines       13724    13785   +61     
=======================================
+ Hits        11018    11068   +50     
- Misses       2137     2143    +6     
- Partials      569      574    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ldetmer ldetmer changed the title chore: add handling for converting newlines in documentoverrides from… chore: add handling for converting newlines in documentoverrides from toml to yaml Dec 18, 2025
@ldetmer ldetmer marked this pull request as ready for review December 18, 2025 14:51
@ldetmer ldetmer requested a review from a team as a code owner December 18, 2025 14:51
@ldetmer ldetmer marked this pull request as draft December 18, 2025 14:54
@ldetmer ldetmer marked this pull request as ready for review December 18, 2025 20:38
@ldetmer ldetmer merged commit ea8f893 into main Dec 18, 2025
13 of 15 checks passed
@ldetmer ldetmer deleted the newline-fix branch December 18, 2025 23:12
zhumin8 added a commit that referenced this pull request Dec 23, 2025
…for documentationoverrides (#3341)

Add on a temp fix on top of the previous fix #3284. This fix tries to
align the expected format for `documentation_overrides` for
`google-cloud-orgpolicy-v1`. This is a brittle change, but as we don't
expect new `documentation_overrides` in the next few days and this is a
one time migration, it should be acceptable.


Verified locally after this change, `librarian generate
google-cloud-orgpolicy-v1` produces no diff. And the only diff it
produced for librarian.yaml is the following:

```
--- a/librarian.yaml
+++ b/librarian.yaml
@@ -1084,14 +1084,16 @@ libraries:
       title_override: Organization Policy Types
       documentation_overrides:
         - id: .google.cloud.orgpolicy.v1.Policy.ListPolicy
-          match: 'Ancestry subtrees must be in one of the following formats:'
+          match: |
+            Ancestry subtrees must be in one of the following formats:
           replace: |
-            
+
             Ancestry subtrees must be in one of the following formats:
         - id: .google.cloud.orgpolicy.v1.Policy.ListPolicy
-          match: The `supports_under` field of the associated `Constraint`  defines whether
+          match: |
+            The `supports_under` field of the associated `Constraint`  defines whether
           replace: |
-            
+
             The `supports_under` field of the associated `Constraint`  defines whether
```

Additional context about this fix:
#3330 (comment)

Fix #3330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal/rust: fix how whitespace is handled for document overrides

2 participants