Skip to content

Conversation

@suztomo
Copy link
Member

@suztomo suztomo commented Oct 23, 2025

This pull requests changes the argument parsing/validation logic of the generate command to languagecontainer package. The corresponding test cases have been moved to the languagecontainer package as well.

As a result, the main.go and main_test.go became simpler.

Test to confirm the generate function is called

suztomo@suztomo:~/sdk-platform-java/internal/librariangen$ docker build .
...
 => => writing image sha256:0e0d003ebd405958e90efd9fd835bcc80ef811be00716c7b5fc9ba8e64dc5eb9
suztomo@suztomo:/tmp/librarian$ docker run --rm -v /tmp/librarian:/tmp/librarian sha256:0e0d003ebd405958e90efd9fd835bcc80ef811be00716c7b5fc9ba8e64dc5eb9 generate -librarian /tmp/librarian
time=2025-10-23T18:10:34.048Z level=INFO msg="librariangen: invoked" args="[/usr/local/bin/librariangen generate -librarian /tmp/librarian]"
time=2025-10-23T18:10:34.049Z level=ERROR msg="generate failed" error="librariangen: failed to unzip /output/java_gapic.zip: open /output/java_gapic.zip: no such file or directory"

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Oct 23, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 significantly refactors the librariangen tool's generate command. The changes introduce a new languagecontainer/generate package to centralize configuration and request parsing, moving this logic out of the main generator file. This architectural shift aims to improve modularity, maintainability, and extensibility by aligning the generation process with a more standardized languagecontainer.Run pattern.

Highlights

  • Refactored Generate Command: The core generate command logic has been refactored to integrate with the new languagecontainer.Run function, promoting a more modular structure.
  • New Configuration Structures: Introduced new generate.Context and generate.Config structs within a dedicated languagecontainer/generate package to encapsulate directory paths and parsed generation requests.
  • Centralized Configuration Handling: Configuration parsing and validation, including reading generate-request.json and validating directory paths, are now centralized within the languagecontainer/generate package.
  • Simplified Generator Logic: The internal/librariangen/generate/generator.go file has been simplified by removing its internal Config struct and Validate method, delegating these responsibilities to the new languagecontainer/generate package.
  • Main CLI Integration: The main.go entry point now leverages languagecontainer.Run to execute the generate command, passing the generate.Generate function as part of the LanguageContainer struct.
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.

)

// Config holds the internal librariangen configuration for the generate command.
type Config struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has moved to languagecontainer.Context.

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.05%. Comparing base (452d703) to head (ef288e5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3968      +/-   ##
==========================================
+ Coverage   78.89%   82.05%   +3.16%     
==========================================
  Files           8        9       +1     
  Lines         379      379              
==========================================
+ Hits          299      311      +12     
+ Misses         53       41      -12     
  Partials       27       27              
Flag Coverage Δ
librariangen 82.05% <ø> (+3.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

// readGenerateReq reads generate-request.json from the librarian-tool input directory.
// The request file tells librariangen which library and APIs to generate.
// It is prepared by the Librarian tool and mounted at /librarian.
func readGenerateReq(librarianDir string) (*message.Library, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has moved to languagecontainer.generate.NewConfig.

Copy link
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 introduces the use of languagecontainer.Run for the generate command, refactors the Generate function to use a generate.Config struct, and adds a new generate package with Context and Config types. The changes also include updates to tests and the main entry point to accommodate the new structure. The review focuses on ensuring the correctness of the new implementation, proper error handling, and adherence to good coding practices.

}

// handleGenerate parses flags for the generate command and calls the generator.
func handleGenerate(ctx context.Context, args []string) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

This moved to languagecontainer package.

@suztomo suztomo marked this pull request as ready for review October 23, 2025 18:11
Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

This is conflicting a lot with #3967. Can you please make the change in two separate PRs.

  1. changes to main.go
  2. changes to generator.go

@suztomo
Copy link
Member Author

suztomo commented Oct 23, 2025

@meltsufin I couldn't think of a good way to split it. main.go starts using languagecontainer.Run which pass new languagecontainer.generate.Config to the Generate command (defined in generator.go). The changes are related. How about merging your pull request first and I deal with the conflicts?

@suztomo
Copy link
Member Author

suztomo commented Oct 23, 2025

@meltsufin I merged the main branch. PTAL.

@suztomo suztomo requested a review from meltsufin October 23, 2025 21:32
@suztomo suztomo merged commit 0a1bbea into main Oct 24, 2025
50 checks passed
@suztomo suztomo deleted the languagecontainer_generate branch October 24, 2025 03:58
meltsufin added a commit that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants