Skip to content

feat: add bl user list and bl user show commands#29

Merged
23prime merged 7 commits intomainfrom
feature/user-commands
Mar 12, 2026
Merged

feat: add bl user list and bl user show commands#29
23prime merged 7 commits intomainfrom
feature/user-commands

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 12, 2026

Checklist

  • Target branch is main
  • Status checks are passing

Summary

  • Add bl user list — lists all users in the space (GET /api/v2/users)
  • Add bl user show <id> — shows a single user by numeric ID (GET /api/v2/users/:userId)
  • Update User struct: userId and mailAddress are now Option<String> to handle bot users; add optional lang and lastLoginTime fields with #[serde(default)]

Reason for change

Space-level user commands were not implemented. This enables listing all members and inspecting individual user details.

Changes

  • src/api/user.rs — extend User struct; add get_users() and get_user() methods
  • src/api/mod.rs — add get_users / get_user to BacklogApi trait
  • src/cmd/user/ — new module with list and show subcommands
  • src/cmd/mod.rs — register pub mod user
  • src/cmd/auth.rs — update user_id access to handle Option<String>
  • src/main.rs — register Commands::User with List and Show subcommands
  • All existing MockApi test stubs updated with unimplemented!() stubs for the two new trait methods

Notes

bl user list requires admin role on the space per the Backlog API specification.

23prime added 2 commits March 12, 2026 19:27
Add GET /api/v2/users (list all space users) and GET /api/v2/users/:userId (show a single user).
Update User struct to handle nullable userId/mailAddress and optional lang/lastLoginTime fields.
Copilot AI review requested due to automatic review settings March 12, 2026 10:29
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Adds user management: new BacklogApi methods get_users and get_user, makes several User fields optional and adds an extra map, implements CLI commands user list and user show (JSON/text), wires commands into main, and updates many test MockApi stubs and docs.

Changes

Cohort / File(s) Summary
Core API trait & client
src/api/mod.rs
Add get_users() -> Result<Vec<User>> and get_user(user_id: u64) -> Result<User> to BacklogApi and delegate impls in BacklogClient.
User model
src/api/user.rs
Make user_id and mail_address Option<String>; add lang, last_login_time (Option via serde default) and extra: BTreeMap<String, Value>; update tests and deserialization.
CLI: user commands
src/cmd/user/list.rs, src/cmd/user/show.rs, src/cmd/user/mod.rs
New UserListArgs/UserShowArgs, list/show functions and helpers; formatting + JSON support; comprehensive tests with MockApi.
CLI wiring
src/main.rs, src/cmd/mod.rs
Export cmd::user module, add User subcommand (List, Show) and dispatch handling in run().
Auth minor update
src/cmd/auth.rs
Safe printing of optional user_id (as_deref().unwrap_or("-")) and test updates for optional fields.
Test MockApi stubs (many)
src/cmd/**/... (e.g. src/cmd/issue/*, src/cmd/project/*, src/cmd/space/*, src/cmd/wiki/*, src/cmd/user/*)
Add get_users and get_user stub implementations to MockApi in numerous test modules to satisfy the expanded BacklogApi trait.
Docs & website
website/docs/commands.md, website/i18n/ja/.../commands.md
Add docs for bl user list and bl user show, mark implemented and include usage/examples.
Misc config/docs
.claude/skills/..., Cargo.toml
Minor documentation step updates and small manifest edits.

Sequence Diagram(s)

sequenceDiagram
    actor CLI as User (CLI)
    participant Main as main.rs
    participant CmdList as cmd::user::list
    participant Client as BacklogClient
    participant API as Backlog API

    CLI->>Main: run 'user list'
    Main->>CmdList: list(UserListArgs)
    CmdList->>Client: BacklogClient::new(...)
    CmdList->>Client: get_users()
    Client->>API: HTTP GET /api/v2/users
    API-->>Client: Vec<User>
    Client-->>CmdList: Result<Vec<User>>
    alt args.json == true
        CmdList->>CLI: pretty JSON
    else
        CmdList->>CLI: formatted rows
    end
Loading
sequenceDiagram
    actor CLI as User (CLI)
    participant Main as main.rs
    participant CmdShow as cmd::user::show
    participant Client as BacklogClient
    participant API as Backlog API

    CLI->>Main: run 'user show --id 123'
    Main->>CmdShow: show(UserShowArgs)
    CmdShow->>Client: BacklogClient::new(...)
    CmdShow->>Client: get_user(123)
    Client->>API: HTTP GET /api/v2/users/123
    API-->>Client: User
    Client-->>CmdShow: Result<User>
    alt args.json == true
        CmdShow->>CLI: pretty JSON
    else
        CmdShow->>CLI: formatted details
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through code with whiskers bright and keen,
I added users, list and show — a tidy little scene.
Optional tails and extra notes tucked in a map,
CLI prints JSON or text rows — I left a carrot for a chap.
Happy hops — the warren greets each user, neat and clean.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.66% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding two new user management CLI commands (user list and user show).
Description check ✅ Passed The pull request description clearly relates to the changeset, describing the addition of two new CLI commands for user management and the corresponding API and struct changes.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/user-commands
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/user-commands

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

Adds space-level user commands to the CLI (bl user list / bl user show <id>) by extending the Backlog API client/trait and updating the User model to handle bot/nullable fields.

Changes:

  • Add bl user list and bl user show <id> subcommands wired into src/main.rs.
  • Extend api::user::User (nullable userId/mailAddress, optional lang/lastLoginTime, flattened extra) and add get_users() / get_user() client + trait methods.
  • Update existing command test mocks to include stubs for the new BacklogApi trait methods.

Reviewed changes

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

Show a summary per file
File Description
src/main.rs Registers user command group and dispatches to cmd::user::{list, show}.
src/cmd/mod.rs Exposes new cmd::user module.
src/cmd/auth.rs Updates auth status output + tests to handle User.user_id: Option<String>; adds new trait method stubs in test mock.
src/api/user.rs Updates User struct (Option fields + extra) and adds get_users/get_user with tests.
src/api/mod.rs Extends BacklogApi trait with get_users/get_user and implements them for BacklogClient.
src/cmd/user/mod.rs Adds cmd user module exports for list/show.
src/cmd/user/list.rs Implements bl user list + unit tests.
src/cmd/user/show.rs Implements bl user show + unit tests.
src/cmd/wiki/update.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/show.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/list.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/history.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/delete.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/create.rs Updates test MockApi to stub get_users/get_user.
src/cmd/wiki/attachment/list.rs Updates test MockApi to stub get_users/get_user.
src/cmd/space/show.rs Updates test MockApi to stub get_users/get_user.
src/cmd/space/notification.rs Updates test MockApi to stub get_users/get_user.
src/cmd/space/disk_usage.rs Updates test MockApi to stub get_users/get_user.
src/cmd/space/activities.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/version.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/user.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/status.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/show.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/list.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/issue_type.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/disk_usage.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/category.rs Updates test MockApi to stub get_users/get_user.
src/cmd/project/activities.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/update.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/show.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/list.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/delete.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/create.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/count.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/comment/update.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/comment/list.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/comment/delete.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/comment/add.rs Updates test MockApi to stub get_users/get_user.
src/cmd/issue/attachment/list.rs Updates test MockApi to stub get_users/get_user.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/cmd/project/status.rs (1)

57-62: Prefer fallible MockApi stubs here.

These new stubs will panic if a later refactor starts calling them. Returning anyhow::bail!("unexpected MockApi::get_users/get_user call") keeps failures on the normal error path, and extracting that into a shared test double would also reduce the trait-expansion boilerplate showing up across command tests.

Example local cleanup
+use anyhow::{anyhow, bail};
+
         fn get_users(&self) -> anyhow::Result<Vec<crate::api::user::User>> {
-            unimplemented!()
+            bail!("unexpected MockApi::get_users call")
         }
         fn get_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
-            unimplemented!()
+            bail!("unexpected MockApi::get_user call")
         }

As per coding guidelines, **/*.rs: Use anyhow for error handling throughout; Never call BacklogClient::from_config() in tests — it requires real credentials on disk. Use httpmock for api/ layer tests and MockApi struct for cmd/ layer tests.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/project/status.rs` around lines 57 - 62, The test MockApi stubs panic
via unimplemented!() which will abort tests if called; change fn get_users and
fn get_user in MockApi to return a fallible anyhow::Result by calling
anyhow::bail!("unexpected MockApi::get_users call") and
anyhow::bail!("unexpected MockApi::get_user call") respectively (or extract a
shared helper used by both stubs) so unexpected calls surface as normal errors
instead of panics; update any tests that construct MockApi to rely on the new
error-returning behavior.
src/main.rs (1)

536-541: Expose the admin-only restriction in the help text.

bl user list is admin-only per the Backlog API, but the generated help currently reads like a general space-wide listing command. Calling that out here will save non-admin users from learning it via a permission error.

💡 Suggested help text
-    /// List users in the space
+    /// List users in the space (admin only)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main.rs` around lines 536 - 541, Update the help text for the List CLI
variant to state the admin-only restriction: change the doc comment above the
List enum variant (the variant named List in the CLI command enum in main.rs)
from "List users in the space" to something like "List users in the space
(admin-only)". If using clap attributes instead of doc comments, add or update
#[clap(long_help = "...")] or #[clap(help = "...")] for the List variant to
include the admin-only note so the generated help shows the restriction.
🤖 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/user/list.rs`:
- Around line 36-40: format_user_row currently hides the numeric u.id when a
user_id exists, breaking the workflow that requires a numeric u64 for commands
like `bl user show`; update format_user_row so the numeric ID (u.id) is always
present in the output and, if a textual user_id exists, include both (e.g.
numeric ID plus the textual user_id) alongside u.name; modify the match in
format_user_row to fall back to or concatenate u.id with u.user_id (using the
function name format_user_row and fields u.id and u.user_id to locate the
change).

---

Nitpick comments:
In `@src/cmd/project/status.rs`:
- Around line 57-62: The test MockApi stubs panic via unimplemented!() which
will abort tests if called; change fn get_users and fn get_user in MockApi to
return a fallible anyhow::Result by calling anyhow::bail!("unexpected
MockApi::get_users call") and anyhow::bail!("unexpected MockApi::get_user call")
respectively (or extract a shared helper used by both stubs) so unexpected calls
surface as normal errors instead of panics; update any tests that construct
MockApi to rely on the new error-returning behavior.

In `@src/main.rs`:
- Around line 536-541: Update the help text for the List CLI variant to state
the admin-only restriction: change the doc comment above the List enum variant
(the variant named List in the CLI command enum in main.rs) from "List users in
the space" to something like "List users in the space (admin-only)". If using
clap attributes instead of doc comments, add or update #[clap(long_help =
"...")] or #[clap(help = "...")] for the List variant to include the admin-only
note so the generated help shows the restriction.
🪄 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: 426e07dc-a066-4a99-aa23-e5946ed7613a

📥 Commits

Reviewing files that changed from the base of the PR and between bab6c53 and 5e37912.

📒 Files selected for processing (39)
  • src/api/mod.rs
  • src/api/user.rs
  • src/cmd/auth.rs
  • src/cmd/issue/attachment/list.rs
  • src/cmd/issue/comment/add.rs
  • src/cmd/issue/comment/delete.rs
  • src/cmd/issue/comment/list.rs
  • src/cmd/issue/comment/update.rs
  • src/cmd/issue/count.rs
  • src/cmd/issue/create.rs
  • src/cmd/issue/delete.rs
  • src/cmd/issue/list.rs
  • src/cmd/issue/show.rs
  • src/cmd/issue/update.rs
  • src/cmd/mod.rs
  • src/cmd/project/activities.rs
  • src/cmd/project/category.rs
  • src/cmd/project/disk_usage.rs
  • src/cmd/project/issue_type.rs
  • src/cmd/project/list.rs
  • src/cmd/project/show.rs
  • src/cmd/project/status.rs
  • src/cmd/project/user.rs
  • src/cmd/project/version.rs
  • src/cmd/space/activities.rs
  • src/cmd/space/disk_usage.rs
  • src/cmd/space/notification.rs
  • src/cmd/space/show.rs
  • src/cmd/user/list.rs
  • src/cmd/user/mod.rs
  • src/cmd/user/show.rs
  • src/cmd/wiki/attachment/list.rs
  • src/cmd/wiki/create.rs
  • src/cmd/wiki/delete.rs
  • src/cmd/wiki/history.rs
  • src/cmd/wiki/list.rs
  • src/cmd/wiki/show.rs
  • src/cmd/wiki/update.rs
  • src/main.rs

Addresses review comment: numeric ID hidden when userId exists, breaking bl user show workflow
@23prime 23prime merged commit 4d7c36f into main Mar 12, 2026
9 checks passed
@23prime 23prime deleted the feature/user-commands branch March 12, 2026 11:27
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.

2 participants