Add imports CLI commands and multipart upload support#2
Conversation
📝 WalkthroughWalkthroughAdds a new "imports" Cobra CLI command (list/show/create/delete), integrates it into the root command, and adds multipart upload support to the internal API client to enable file-based import creation (with dry-run vs --apply behavior and input validation). Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as Imports CLI
participant APIClient as API Client
participant APIServer as API Server
User->>CLI: run `imports create --apply --file path --source S --account A --file-format F`
CLI->>CLI: validate flags, check file exists and type, detect/resolve format
CLI->>CLI: build form fields map and attach file
CLI->>APIClient: PostMultipart("/api/v1/imports", fields, "file", path)
APIClient->>APIClient: refresh token if needed
APIClient->>APIServer: POST /api/v1/imports (multipart/form-data)
APIServer->>APIClient: 200 / error response
APIClient->>CLI: parsed response or error
CLI->>User: print result or failure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @jjmata, 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 CLI by integrating import management capabilities, allowing users to interact with import resources directly from the command line. It also introduces robust file upload support, making it easier to process various financial data formats. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request introduces new CLI commands for managing imports, including support for multipart file uploads. The implementation is well-structured, following existing patterns in the CLI. My review focuses on improving error handling and code clarity. I've pointed out several places where errors are ignored, which could lead to silent failures. I've also suggested a more idiomatic way to construct URLs. A major concern is the lack of automated tests for this new functionality, as stated in the PR description. Adding tests would significantly improve the robustness and maintainability of these changes.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/api/client.go`:
- Around line 114-129: In Client.PostMultipart validate the file parameters
before building the request: if exactly one of fileField or filePath is
non-empty, return a descriptive error (e.g., via fmt.Errorf or errors.New)
instead of silently omitting the file; keep the ensureFreshToken() check first,
then check the file arguments and only proceed to call SetFile(fileField,
filePath) when both are provided, otherwise fail fast with the clear error so
callers know they passed mismatched file args.
There was a problem hiding this comment.
Good stuff, but there's a flag collision to sort out.
The --format flag here shadows the global output format flag (json|table). This means users can't control output format for this command — breaks CLI consistency.
Rename to --file-format or --import-format and we're good to merge.
🐙🤖
- Rename --format to --file-format to avoid collision with global output flag - Handle output.Print errors instead of ignoring them - Panic on MarkFlagRequired error (catches programming mistakes) - Use url.URL struct for cleaner URL construction - Validate fileField/filePath consistency in PostMultipart
dgilperez
left a comment
There was a problem hiding this comment.
Fixed all the issues in commit 7f99352:
• --format → --file-format (no more collision with global output flag)
• output.Print errors now handled
• MarkFlagRequired panics on error
• URL construction uses url.URL struct
• PostMultipart validates fileField/filePath consistency
Good to merge.
🐙🤖
dgilperez
left a comment
There was a problem hiding this comment.
Code fixes are in, but this PR still needs tests.
New commands (list, show, create, delete) and the PostMultipart helper should have basic test coverage before merging.
🐙🤖
- imports_cmd_test.go: flag verification, buildImportCreatePayload tests - client_test.go: PostMultipart multipart upload, mismatched args validation - Verify --file-format doesn't collide with global --format
dgilperez
left a comment
There was a problem hiding this comment.
Tests added. All checks pass. Good to merge.
🐙🤖
Motivation
/api/v1/importsendpoints so users can list, view, create (file upload) and delete imports from the CLI.Description
importscommand group withlist,show,create, anddeletesubcommands incmd/sure-cli/root/imports_cmd.gothat mirror other resource commands and follow dry-run/--applysemantics.createpayload construction with file validation and automatic format detection from extension (or explicit--format) inbuildImportCreatePayloadand prepare form fields for upload.PostMultiparthelper to the API client ininternal/api/client.goto send form data and a file via multipart POST usingSetFormDataandSetFile.importscommand in the root CLI wiring by addingcmd.AddCommand(newImportsCmd())incmd/sure-cli/root/root.go.Testing
Codex Task
Summary by CodeRabbit
New Features
Tests