fix(internal/librarian/golang): update version in snippet metadata#3945
Open
JoeWang1127 wants to merge 7 commits intomainfrom
Open
fix(internal/librarian/golang): update version in snippet metadata#3945JoeWang1127 wants to merge 7 commits intomainfrom
JoeWang1127 wants to merge 7 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces functionality to update a version placeholder in snippet metadata files. The implementation in generate.go uses filepath.Walk to find and update the files. A corresponding test is added in generate_test.go.
My review includes two main points:
- A suggestion to improve the performance of the file traversal by using
filepath.WalkDir. - A more significant concern with the new test
TestUpdateSnippetMetadata, which is currently not testing the replacement logic correctly and modifies files in thetestdatadirectory. I've provided a complete rewrite of the test to make it robust and self-contained, also noting that the suggested fix aligns with the rule of usingt.Fatalfor error handling in Go tests.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3945 +/- ##
==========================================
- Coverage 83.35% 83.29% -0.07%
==========================================
Files 69 69
Lines 6188 6207 +19
==========================================
+ Hits 5158 5170 +12
- Misses 671 675 +4
- Partials 359 362 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jameslynnwu
reviewed
Feb 7, 2026
| return cerr | ||
| } | ||
|
|
||
| func updateSnippetMetadata(library *config.Library, output string) error { |
Contributor
There was a problem hiding this comment.
pull over the doc strings
also, I think we should start logging more things, similar to how legacy librarian does so.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace placeholder with library version in snippet metadata file.
The logic is similar in go generator used in legacylibrarian:
https://github.com/googleapis/google-cloud-go/blob/b3409e6d7fbb5708e6be6000a1257a741c23b63b/internal/librariangen/module/module.go#L72
The file is read in one-go and modified in-place, which is not ideal if the file is too large. However, the metadata file is ~500 lines so this straightforward implementation should be suffice.
For #3617