feat: add bl user list and bl user show commands#29
Conversation
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.
📝 WalkthroughWalkthroughAdds user management: new BacklogApi methods Changes
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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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)
✨ 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 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 listandbl user show <id>subcommands wired intosrc/main.rs. - Extend
api::user::User(nullableuserId/mailAddress, optionallang/lastLoginTime, flattenedextra) and addget_users()/get_user()client + trait methods. - Update existing command test mocks to include stubs for the new
BacklogApitrait 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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/cmd/project/status.rs (1)
57-62: Prefer fallibleMockApistubs 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: Useanyhowfor error handling throughout;Never call BacklogClient::from_config()in tests — it requires real credentials on disk. Usehttpmockforapi/layer tests andMockApistruct forcmd/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 listis 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
📒 Files selected for processing (39)
src/api/mod.rssrc/api/user.rssrc/cmd/auth.rssrc/cmd/issue/attachment/list.rssrc/cmd/issue/comment/add.rssrc/cmd/issue/comment/delete.rssrc/cmd/issue/comment/list.rssrc/cmd/issue/comment/update.rssrc/cmd/issue/count.rssrc/cmd/issue/create.rssrc/cmd/issue/delete.rssrc/cmd/issue/list.rssrc/cmd/issue/show.rssrc/cmd/issue/update.rssrc/cmd/mod.rssrc/cmd/project/activities.rssrc/cmd/project/category.rssrc/cmd/project/disk_usage.rssrc/cmd/project/issue_type.rssrc/cmd/project/list.rssrc/cmd/project/show.rssrc/cmd/project/status.rssrc/cmd/project/user.rssrc/cmd/project/version.rssrc/cmd/space/activities.rssrc/cmd/space/disk_usage.rssrc/cmd/space/notification.rssrc/cmd/space/show.rssrc/cmd/user/list.rssrc/cmd/user/mod.rssrc/cmd/user/show.rssrc/cmd/wiki/attachment/list.rssrc/cmd/wiki/create.rssrc/cmd/wiki/delete.rssrc/cmd/wiki/history.rssrc/cmd/wiki/list.rssrc/cmd/wiki/show.rssrc/cmd/wiki/update.rssrc/main.rs
Addresses review comment: numeric ID hidden when userId exists, breaking bl user show workflow
Checklist
mainSummary
bl user list— lists all users in the space (GET /api/v2/users)bl user show <id>— shows a single user by numeric ID (GET /api/v2/users/:userId)Userstruct:userIdandmailAddressare nowOption<String>to handle bot users; add optionallangandlastLoginTimefields 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— extendUserstruct; addget_users()andget_user()methodssrc/api/mod.rs— addget_users/get_usertoBacklogApitraitsrc/cmd/user/— new module withlistandshowsubcommandssrc/cmd/mod.rs— registerpub mod usersrc/cmd/auth.rs— updateuser_idaccess to handleOption<String>src/main.rs— registerCommands::UserwithListandShowsubcommandsunimplemented!()stubs for the two new trait methodsNotes
bl user listrequires admin role on the space per the Backlog API specification.