-
Notifications
You must be signed in to change notification settings - Fork 68
chore(librariangen): languagecontainer package to parse release-init request #3965
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
Summary of ChangesHello @suztomo, 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 significant architectural change by creating a new Highlights
Using Gemini Code AssistThe 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
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 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
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3965 +/- ##
==========================================
- Coverage 88.37% 80.27% -8.11%
==========================================
Files 6 8 +2
Lines 370 441 +71
==========================================
+ Hits 327 354 +27
- Misses 30 68 +38
- Partials 13 19 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| cmd := args[0] | ||
| flags := args[1:] | ||
| switch cmd { | ||
| case "generate": |
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'll move the generate command parsing here. Once Mike's generate command work stop having conflict.
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 don't have any outstanding PRs right now. I think it's OK to move it. I can deal with the merge with my WIP.
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'll change that in a subsequent pull request.
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
This pull request introduces a new languagecontainer package to abstract command execution, starting with the release-init command. The refactoring in main.go delegates command handling to this new package, which is a good step towards modularity. My feedback focuses on improving robustness by avoiding panics, adhering to structured logging best practices, enhancing test clarity, and addressing a regression in test coverage in main_test.go.
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestRun(t *testing.T) { |
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 test is from main_test.go
| "cloud.google.com/java/internal/librariangen/generate" | ||
| ) | ||
|
|
||
| func TestRun(t *testing.T) { |
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 goes to languagecontainer_test.go.
2d0b042 to
28cb6cd
Compare
…request The languagecontainer package parses the request JSON file and calls the corresponding implementation method. The user (Java's language container in this case) doesn't have to implement the parsing logic and the tests. I moved the argument parsing tests to languagecontainer/languagecontainer_test.go from main_test.go.
28cb6cd to
75337ca
Compare
|
Thank you Gemini Code Assist. I added that to the PR description. |
meltsufin
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 think ideally this would be two separate PRs, one for introducing languagecontainer, and another for adding release-init command support.
| case "configure": | ||
| slog.Warn("librariangen: configure command is not yet implemented") | ||
| return 1 | ||
| case "release-init": |
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 think this is a lot code to put into a switch statement. Do you think it would make sense to move it to a separate function, like it was done for generate?
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.
Let me work on 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.
Added handleReleaseInit here.
| cmd := args[0] | ||
| flags := args[1:] | ||
| switch cmd { | ||
| case "generate": |
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 don't have any outstanding PRs right now. I think it's OK to move it. I can deal with the merge with my WIP.
| ) | ||
|
|
||
| // LanguageContainer defines the functions for language-specific container operations. | ||
| type LanguageContainer struct { |
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.
Why not use an interface here?
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.
If this is an interface, then there would be package name conflict of languagecontainer/release package (language agostic) and release package (language-specific. In this case Java-specific). Here is a piece of code when I tried to introduce languagecontainer/release and release packages. The naming conflict happened and I had to rename one of them to release2:
package main
import (
... (omit)...
"cloud.google.com/java/internal/librariangen/generate"
release2 "cloud.google.com/java/internal/librariangen/languagecontainer/release"
"cloud.google.com/java/internal/librariangen/message"
"cloud.google.com/java/internal/librariangen/release"
)
... (omit)...
// javaContainer implements the LanguageContainer interface for Java.
type javaContainer struct{}
// ReleaseInit implements the LanguageContainer interface for Java.
func (c *javaContainer) ReleaseInit(ctx context.Context, cfg *release2.Config) (*message.ReleaseInitResponse, error) {
return release.Init(ctx, cfg)
}
I just added this observation in the description of this pull requests.
CC: @codyoss We talked about interface v.s. a struct with functions. I now think the struct is better because we don't have to rename "languagecontainer/release" package when we use (language-specific) "release" package used in main.go.
I thought about that too, but I think it's more clear if the introduction of languagecontainer has one usage of the package. Subsequent pull requests will be more fine-grained. |
| } | ||
|
|
||
| // Run accepts an implementation of the LanguageContainer. | ||
| func Run(args []string, container LanguageContainer) int { |
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.
Should this be a pointer *LanguageContainer?
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.
Yes, that's a good catch. Updated to use a pointer.
| cmd := args[0] | ||
| flags := args[1:] | ||
| switch cmd { | ||
| case "generate": |
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 would imagine you would check if the passed in LanguageContainer struct includes the corresponding functions, and if so invoke them, otherwise log the warning.
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.
Yes, that's the plan. In this pull requests, LanguageContainer only has ReleaseInit function.
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.
Added that in #3968.
meltsufin
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 approved it, but then I noticed the code coverage dropping by 8.11%. Can you look into this please?
|
@meltsufin I checked the coverage (
|
|
I temporarily removed "build (11)", "build (17)", and "showcase (25)". |
@meltsufin Created #3968. |

Introducing languagecontainer package.
New languagecontainer package: A new
languagecontainerpackage has been introduced to encapsulate language-specific container operations and command execution logic, promoting modularity. This package parses the request JSON file and calls thecorresponding implementation method in each language container. The languagecontainer package itself should not have language-specific implementation.
languagecontainer.Runfunction now includes robust logic to parserelease-initrequests from JSON files, handle command-line flags, and invoke theReleaseInitfunction.LanguageContaineris an interface, then there would be package name conflict oflanguagecontainer/releasepackage (language agostic) andreleasepackage (language-specific. In this case Java-specific). Here is a piece of code.Main command dispatch refactor: The
librariangenmain.gohas been refactored to delegate non-generatecommands to the newlanguagecontainer.Runfunction, centralizing command execution and wiring uprelease.Initfor therelease-initcommand.message.Change struct update: The
SourceCommitHashfield in themessage.Changestruct has been renamed toCommitHashfor improved clarity and consistency. This is due to the recent renaming of the field and google-cloud-go/internal/librariangen/request.Change already has the field.The user (Java's language container in this case) doesn't have to implement the parsing logic and the tests. I moved the argument parsing tests to languagecontainer/languagecontainer_test.go from main_test.go.