Skip to content

feat: implement bl user icon (GET /api/v2/users/{userId}/icon)#124

Merged
1 commit merged intomainfrom
feature/120-user-icon
Mar 22, 2026
Merged

feat: implement bl user icon (GET /api/v2/users/{userId}/icon)#124
1 commit merged intomainfrom
feature/120-user-icon

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 22, 2026

Checklist

  • Target branch is main
  • Status checks are passing
  • Documentation updated if user-visible behavior changed (website/docs/, website/i18n/ja/, README.md)

Summary

  • Add bl user icon <id> command to download a user's icon image
  • Supports --output / -o to specify the save path; defaults to the server-provided filename (or user_icon when the filename is missing or a generic attachment placeholder)
  • default_output_path applies the attachment check on the basename after file_name() extraction, consistent with the approach adopted in feat: implement bl project image (GET /api/v2/projects/{projectIdOrKey}/image) #123

Reason for change

Implements GET /api/v2/users/{userId}/icon so all published Backlog API v2 endpoints in the Users category are covered.

Changes

  • src/api/user.rs — add download_user_icon(user_id)
  • src/api/mod.rs — add download_user_icon to BacklogApi trait and impl BacklogApi for BacklogClient
  • src/cmd/user/icon.rs — new command with icon() / icon_with() / default_output_path() and unit tests
  • src/cmd/user/mod.rs — re-export UserIconArgs and icon
  • src/main.rs — add UserCommands::Icon variant and dispatch
  • website/docs/commands.md, website/i18n/ja/.../commands.md — add command docs and mark as implemented

Notes

Tested against real Backlog API: bl user icon 972384Saved: user_icon (878 bytes).

Closes #120

Copilot AI review requested due to automatic review settings March 22, 2026 14:19
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d6e279b-a144-4d27-823d-a4e76864fa32

📥 Commits

Reviewing files that changed from the base of the PR and between 89bbd1e and 69bf2b5.

📒 Files selected for processing (7)
  • src/api/mod.rs
  • src/api/user.rs
  • src/cmd/user/icon.rs
  • src/cmd/user/mod.rs
  • src/main.rs
  • website/docs/commands.md
  • website/i18n/ja/docusaurus-plugin-content-docs/current/commands.md

📝 Walkthrough

Walkthrough

Implements the bl user icon <userId> command to download user icon images from the Backlog API. Adds a new trait method and client implementation in the API layer, a CLI subcommand with optional file output, and default filename fallback logic. Includes English and Japanese documentation.

Changes

Cohort / File(s) Summary
API Layer
src/api/mod.rs, src/api/user.rs
Added download_user_icon(&self, user_id: u64) method to BacklogApi trait with default unimplemented body and corresponding BacklogClient implementation that issues a request to /users/{user_id}/icon and returns binary data with filename.
CLI Command
src/cmd/user/icon.rs, src/cmd/user/mod.rs, src/main.rs
Added new UserIconArgs struct and icon/icon_with functions to download user icons and save to disk. Includes default filename derivation logic (normalizes server filename, falls back to "user_icon" for attachments). Added UserCommands::Icon subcommand with id and optional --output/-o flag. Contains unit tests with MockApi for output path, error propagation, and filename selection.
Documentation
website/docs/commands.md, website/i18n/ja/docusaurus-plugin-content-docs/current/commands.md
Added documentation for bl user icon <id> command describing binary download behavior, --output flag, default filename handling, and updated command coverage table marking the endpoint as implemented.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as CLI<br/>(main.rs)
    participant CmdIcon as icon Module<br/>(cmd/user/icon.rs)
    participant API as BacklogClient<br/>(api/user.rs)
    participant Server as Backlog Server
    participant FS as File System

    User->>CLI: Run `bl user icon <id> --output <path>`
    CLI->>CmdIcon: icon(UserIconArgs)
    CmdIcon->>API: download_user_icon(user_id)
    API->>Server: GET /users/{userId}/icon
    Server-->>API: Binary data + filename
    API-->>CmdIcon: Result<(Vec<u8>, String)>
    CmdIcon->>CmdIcon: Derive output path<br/>(use provided or default)
    CmdIcon->>FS: Write bytes to file
    FS-->>CmdIcon: Success/Error
    CmdIcon->>CLI: Result with path & byte count
    CLI-->>User: Print success message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #101: Both add download-style trait methods to BacklogApi with default unimplemented!() bodies and corresponding BacklogClient forwarding implementations, following the same API extension pattern.
  • PR #95: Both extend BacklogApi and BacklogClient with new download methods returning (Vec<u8>, String) tuples and add matching CLI commands for downloading binary resources.
  • PR #122: Both add analogous download image APIs and CLI commands, modifying the same BacklogApi trait and BacklogClient implementation structure for binary resource retrieval.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: implement bl user icon (GET /api/v2/users/{userId}/icon)' clearly and specifically describes the main change: implementing a new CLI command to download user icons.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the command implementation, API endpoint covered, file changes, testing, and linking to issue #120.
Linked Issues check ✅ Passed The PR fully implements issue #120 requirements: adds download_user_icon API method [src/api/user.rs, src/api/mod.rs], creates bl user icon subcommand with --output support [src/cmd/user/icon.rs], implements default filename fallback, updates documentation, and includes unit tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing issue #120: API layer additions, command implementation, CLI wiring, documentation updates, and tests—no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/120-user-icon

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements the remaining Backlog API v2 Users-category endpoint for downloading a user icon, exposing it via a new bl user icon <id> CLI subcommand and documenting it in the command reference.

Changes:

  • Add GET /api/v2/users/{userId}/icon support in the API layer (download_user_icon).
  • Add bl user icon <id> command with --output/-o and default filename fallback behavior.
  • Update English/Japanese command docs and the endpoint-to-command coverage table.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/api/user.rs Adds BacklogClient::download_user_icon(user_id) endpoint wrapper.
src/api/mod.rs Exposes download_user_icon on BacklogApi and forwards it in BacklogClient impl.
src/cmd/user/icon.rs New command implementation, default output-path logic, and unit tests for cmd-layer behavior.
src/cmd/user/mod.rs Wires the new icon subcommand module and re-exports args/entrypoint.
src/main.rs Adds the user icon clap subcommand and dispatch to cmd::user::icon.
website/docs/commands.md Documents bl user icon and marks the endpoint as implemented.
website/i18n/ja/.../commands.md Japanese documentation + coverage table update for bl user icon.

Comment on lines +149 to +151
pub fn download_user_icon(&self, user_id: u64) -> Result<(Vec<u8>, String)> {
self.download(&format!("/users/{user_id}/icon"))
}
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

download_user_icon is a new API endpoint but src/api/user.rs already has httpmock-based coverage for other user endpoints. Please add a unit test that exercises this method (e.g., mock GET /users/{id}/icon returning a binary body and a Content-Disposition filename) and asserts the returned bytes + filename.

Copilot uses AI. Check for mistakes.
Icon {
/// User numeric ID
id: u64,
/// Output file path (default: server-provided filename, or "user_icon" if none)
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

The CLI help text for --output says the fallback is "user_icon" "if none", but the implementation also falls back when the server-provided filename is a generic attachment placeholder. Please update the help text to match the actual behavior so users aren’t surprised by the default filename choice.

Suggested change
/// Output file path (default: server-provided filename, or "user_icon" if none)
/// Output file path (default: server-provided filename; if missing or a generic
/// "attachment" placeholder, falls back to "user_icon")

Copilot uses AI. Check for mistakes.
@23prime 23prime closed this pull request by merging all changes into main in a02081f Mar 22, 2026
@23prime 23prime deleted the feature/120-user-icon branch March 22, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement bl user icon (GET /api/v2/users/{userId}/icon)

2 participants