feat: implement bl space image (GET /api/v2/space/image)#122
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a new CLI command Changes
Sequence DiagramsequenceDiagram
participant User as User
participant CLI as "CLI (main.rs)"
participant Handler as "space/image.rs"
participant API as "BacklogClient"
participant Server as "Backlog Server"
participant FS as "File System"
User->>CLI: bl space image [--output path]
CLI->>Handler: image(&SpaceImageArgs)
Handler->>API: download_space_image()
API->>Server: GET /api/v2/space/image
Server->>API: returns (bytes, filename)
API->>Handler: Result<(Vec<u8>, String)>
Handler->>Handler: determine output path (arg or default)
Handler->>FS: write(path, bytes)
FS-->>Handler: write result
Handler->>User: print "Saved: <path> (<n> bytes)"
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
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 |
There was a problem hiding this comment.
Pull request overview
Adds support for Backlog API v2 GET /api/v2/space/image and exposes it via a new bl space image CLI subcommand to download the space icon image, with corresponding command documentation updates.
Changes:
- Implement
download_space_image()in the API layer and expose it via theBacklogApitrait. - Add
bl space imagecommand (with--output/-o) plus unit tests for the command behavior. - Update English/Japanese command docs and mark the endpoint as implemented in the coverage tables.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/api/space.rs |
Adds a BacklogClient::download_space_image() wrapper over the shared download helper. |
src/api/mod.rs |
Extends BacklogApi with download_space_image and wires the client implementation. |
src/cmd/space/image.rs |
New command implementation to download and write the space icon image, with unit tests. |
src/cmd/space/mod.rs |
Registers/re-exports the new space image command and args. |
src/main.rs |
Adds SpaceCommands::Image clap variant and dispatches to the new command. |
website/docs/commands.md |
Documents bl space image and marks the endpoint as implemented. |
website/i18n/ja/.../commands.md |
Japanese docs for bl space image and endpoint coverage update. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/api/space.rs (1)
26-27: Add a direct API-layer test for/space/image.The command tests are mock-based, so this literal path and its
(bytes, filename)result are currently unpinned. A smallhttpmockcase here would catch route typos and filename/body regressions.🧪 Suggested test
+ #[test] + fn download_space_image_returns_bytes_and_filename() { + let server = MockServer::start(); + server.mock(|when, then| { + when.method(GET).path("/space/image"); + then.status(200) + .header( + "content-disposition", + r#"attachment; filename="space_image.png""#, + ) + .body("png"); + }); + + let client = BacklogClient::new_with(&server.base_url(), "test-key").unwrap(); + let (bytes, filename) = client.download_space_image().unwrap(); + + assert_eq!(filename, "space_image.png"); + assert_eq!(bytes, b"png".to_vec()); + }As per coding guidelines,
api/layer tests should usehttpmockto spin up a local HTTP server and constructBacklogClient::new_with(base_url, api_key)instead of callingBacklogClient::from_config().🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/api/space.rs` around lines 26 - 27, Add a new api-layer test that spins up an httpmock server for the "/space/image" route and asserts the (Vec<u8>, filename) tuple returned by BacklogClient::download_space_image; specifically, configure the mock to respond with the expected binary body and Content-Disposition (or filename) header, construct the client with BacklogClient::new_with(base_url, api_key) (not from_config), call download_space_image (which delegates to download), and assert the returned bytes and filename match the mock values to catch path/filename regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@website/docs/commands.md`:
- Around line 154-166: Update the `bl space image` docs to explicitly state the
response is binary image data and that the `--output`/`-o` flag controls the
destination filename; describe the default behavior when omitted (write to the
current directory with a default name such as space_image.png and print a
"Saved: ..." message) and add the same note to the Japanese translation page;
target the `bl space image` section and mention the `--output`/`-o` flags and
the example "Saved: space_image.png" output so readers understand where the file
goes and what to expect.
---
Nitpick comments:
In `@src/api/space.rs`:
- Around line 26-27: Add a new api-layer test that spins up an httpmock server
for the "/space/image" route and asserts the (Vec<u8>, filename) tuple returned
by BacklogClient::download_space_image; specifically, configure the mock to
respond with the expected binary body and Content-Disposition (or filename)
header, construct the client with BacklogClient::new_with(base_url, api_key)
(not from_config), call download_space_image (which delegates to download), and
assert the returned bytes and filename match the mock values to catch
path/filename regressions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 50f22670-6a72-4834-bb00-19d9c4645f86
📒 Files selected for processing (7)
src/api/mod.rssrc/api/space.rssrc/cmd/space/image.rssrc/cmd/space/mod.rssrc/main.rswebsite/docs/commands.mdwebsite/i18n/ja/docusaurus-plugin-content-docs/current/commands.md
…eric
Addresses review comment: add explicit check for missing/placeholder filenames ("attachment") and substitute domain-specific default
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/cmd/space/image.rs`:
- Around line 33-38: The fallback in function default_output_path currently only
treats the exact string "attachment" as a placeholder; update the condition to
also detect common placeholder variants (e.g., "attachment.png", "attachment-1",
etc.) by replacing the equality check with a starts_with check (e.g.,
filename.is_empty() || filename.starts_with("attachment")), so the effective
name becomes "space_image" for those cases; keep the rest of default_output_path
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b4dc9cf-e215-4537-ba0f-ff583f64de72
📒 Files selected for processing (2)
src/cmd/space/image.rssrc/main.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main.rs
…_path Addresses review comment: fallback was too narrow — only exact "attachment" was handled
Checklist
mainwebsite/docs/,website/i18n/ja/,README.md)Summary
bl space imagecommand to download the space icon image--output <path>(-o) to specify the save path; defaults to the server-provided filenameReason for change
Implements the remaining
GET /api/v2/space/imageendpoint so all published Backlog API v2 endpoints in the Space category are covered.Changes
src/api/space.rs— adddownload_space_image()src/api/mod.rs— adddownload_space_imagetoBacklogApitrait andimpl BacklogApi for BacklogClientsrc/cmd/space/image.rs— new command withimage()/image_with()and unit testssrc/cmd/space/mod.rs— re-exportSpaceImageArgsandimagesrc/main.rs— addSpaceCommands::Imagevariant and dispatchwebsite/docs/commands.md,website/i18n/ja/.../commands.md— add command docs and mark as implementedNotes
Closes #118