Skip to content

feat: add zod runtime validation for external APIs and user inputs#115

Merged
kubrickcode merged 1 commit intomainfrom
develop/shlee/109
Nov 24, 2025
Merged

feat: add zod runtime validation for external APIs and user inputs#115
kubrickcode merged 1 commit intomainfrom
develop/shlee/109

Conversation

@kubrickcode
Copy link
Copy Markdown
Owner

Added zod schemas to validate GitHub API responses and user inputs at runtime
to catch type mismatches that TypeScript cannot detect at compile time

  • GitHub API responses: validate default_branch field with GitHubRepositorySchema
  • BaedalOptions: validate conflictMode, exclude, and token with strict mode
  • CLI options: validate all input parameters with PullCLIOptionsSchema

fix #109

@github-actions github-actions Bot added the refactor Refactoring code label Nov 24, 2025
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @kubrickcode, 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 enhances the application's robustness by integrating Zod for comprehensive runtime validation. It ensures that data received from external APIs and user-provided inputs conform to expected schemas, thereby preventing common type-related errors that TypeScript cannot catch at compile time. This change improves the reliability and stability of the system by proactively identifying and handling malformed data.

Highlights

  • Runtime Validation for GitHub API Responses: Introduced Zod schema (GitHubRepositorySchema) to validate the default_branch field in GitHub API responses, ensuring data integrity from external sources.
  • Runtime Validation for Baedal Options: Implemented Zod schema (BaedalOptionsSchema) for BaedalOptions, validating conflictMode, exclude, and token with strict mode to prevent unexpected properties.
  • Runtime Validation for CLI Inputs: Added Zod schema (PullCLIOptionsSchema) to validate all CLI input parameters, catching type mismatches and invalid values at runtime.
  • Comprehensive Test Coverage: New test suites have been added for all Zod schemas and their integration points, ensuring robust validation logic for both API responses and user inputs.
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

@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 Zod for runtime validation of external API responses and user inputs, which is a great step towards improving the robustness of the application. The implementation is solid, with new schemas for GitHub API responses, BaedalOptions, and CLI options, along with corresponding tests.

My review focuses on opportunities to further centralize validation logic within the new Zod schemas, which would improve maintainability and reduce code duplication. I've suggested refactoring the validation for CLI option conflicts and exclude patterns into the Zod schemas. I also found some redundant tests that could be removed to streamline the test suite. Overall, these are excellent changes.

Comment thread src/cli/adapter.ts Outdated
Comment thread src/cli/types.ts Outdated
Comment thread src/internal/infra/index.ts Outdated
Comment thread src/pkg/pull/types.ts
Comment thread src/pkg/pull/validation.spec.ts Outdated
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is a great improvement for the project's robustness. By introducing Zod for runtime validation of external API responses and user inputs, it effectively catches type mismatches that TypeScript can't detect at compile time. The implementation is well-structured, with new schemas for GitHub API responses, BaedalOptions, and CLI options. The use of a generic parseGitHubResponse helper is a good pattern for handling API validation consistently. I have a few suggestions to improve code consistency and reduce duplication.

Comment thread src/cli/adapter.spec.ts
Comment thread src/pkg/pull/index.ts Outdated
Comment thread src/pkg/pull/types.ts
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is a great step towards improving runtime type safety by introducing Zod for validating external API responses and user inputs. The new schemas for CLI options, Baedal options, and GitHub API responses are well-defined and the accompanying tests are thorough. My review focuses on a few opportunities to improve maintainability by reducing code duplication in the new validation and error handling logic, and by removing some now-redundant validation code. These changes will help keep the codebase clean and adhere to the DRY principle.

Comment thread src/cli/adapter.ts Outdated
Comment thread src/pkg/pull/index.ts Outdated
Comment thread src/pkg/pull/index.ts Outdated
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is a great enhancement, introducing Zod for runtime validation of CLI options, library options, and GitHub API responses. This significantly improves robustness and maintainability by replacing manual validation logic with declarative and type-safe schemas. The changes are well-structured, with new helper functions for Zod parsing and dedicated schema files. I've identified a few areas for minor improvements to enhance conciseness and consistency, which are detailed in the specific comments.

Comment thread src/internal/utils/zod-helpers.ts Outdated
Comment thread src/pkg/pull/types.ts
Comment thread src/pkg/pull/types.ts Outdated
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is a great improvement, introducing Zod for runtime validation of GitHub API responses and user inputs, which significantly enhances the application's robustness. The implementation is well-executed with thorough tests. My feedback includes a few suggestions to improve validation consistency, enhance test clarity, and better align the code structure with the repository's style guide concerning separation of concerns. Overall, this is a solid and valuable contribution.

Comment thread src/cli/types.ts Outdated
Comment thread src/internal/infra/schemas.spec.ts Outdated
Comment thread src/pkg/pull/index.ts
Added zod schemas to validate GitHub API responses and user inputs at runtime
to catch type mismatches that TypeScript cannot detect at compile time

- GitHub API responses: validate default_branch field with GitHubRepositorySchema
- BaedalOptions: validate conflictMode, exclude, and token with strict mode
- CLI options: validate all input parameters with PullCLIOptionsSchema

fix #109
@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is a great enhancement, introducing Zod for runtime validation of API responses and user inputs. This significantly improves the robustness and type safety of the application. The refactoring of existing validation logic into declarative Zod schemas is well-executed, and the creation of a reusable parseWithZod helper function is a smart move for maintainability. The accompanying tests are thorough and correctly validate the new behavior. My review includes one suggestion related to coding conventions to further improve the code quality.

Comment thread src/pkg/pull/index.ts
@kubrickcode kubrickcode merged commit 74eb1aa into main Nov 24, 2025
4 checks passed
@kubrickcode kubrickcode deleted the develop/shlee/109 branch November 24, 2025 12:46
@kubrickcode
Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

refactor Refactoring code released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add zod runtime validation for external APIs and user inputs

1 participant