Skip to content

feat: add bl team add / update / delete / icon commands#105

Merged
23prime merged 4 commits intomainfrom
feature/56-team-add-update-delete
Mar 22, 2026
Merged

feat: add bl team add / update / delete / icon commands#105
23prime merged 4 commits intomainfrom
feature/56-team-add-update-delete

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 mutating bl team commands and icon download:

  • bl team add --name <name> [--member <id>...]POST /api/v2/teams
  • bl team update <id> --name <name> | --member <id>...PATCH /api/v2/teams/{teamId}
  • bl team delete <id>DELETE /api/v2/teams/{teamId}
  • bl team icon <id> [--output <path>]GET /api/v2/teams/{teamId}/icon

Reason for change

Implements the remaining team management commands planned in Issue #56.

Changes

  • src/api/team.rs: Added create_team, update_team, delete_team, download_team_icon
  • src/api/mod.rs: Added trait methods and BacklogClient dispatch
  • src/cmd/team/add.rs, update.rs, delete.rs, icon.rs: New command files with tests
  • src/cmd/team/mod.rs: Re-exports for new commands
  • src/main.rs: Clap wiring for Add, Update, Delete, Icon variants in TeamCommands
  • Docs: Command documentation and coverage table updated (EN + JA)

Notes

POST/PATCH/DELETE commands were not tested against the real API to avoid affecting live data.

Closes #56

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

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

Adds team management: new BacklogApi trait methods and BacklogClient team implementations; four CLI subcommands (team add/update/delete/icon) with argument types, wiring, output handling and tests; shared formatting helper moved; docs, i18n, testing notes, and a spellcheck token added.

Changes

Cohort / File(s) Summary
API trait & client
src/api/mod.rs, src/api/team.rs
Added create_team, update_team, delete_team, download_team_icon to BacklogApi and BacklogClient; download_team_icon returns (Vec<u8>, String); JSON deserialization errors include pretty-printed raw JSON in error context; tests added for parsing and icon download.
CLI command implementations
src/cmd/team/add.rs, src/cmd/team/update.rs, src/cmd/team/delete.rs, src/cmd/team/icon.rs
New command modules with argument structs and *_with testable functions that call BacklogApi, build form params (including repeated members[]), handle JSON/text output, and for icon write bytes to disk with contextual error messages; unit tests included.
CLI surface & integration
src/cmd/team/mod.rs, src/cmd/team/list.rs
Re-exported new subcommands and args; added shared format_team_row (moved from list); list.rs updated to call super::format_team_row.
CLI wiring
src/main.rs
Added team add/update/delete/icon Clap variants and dispatch logic; converts member list to Option<Vec<u64>> for update.
Docs & i18n
website/docs/commands.md, website/i18n/ja/.../commands.md
Added usage, examples, and sample output for new team commands; updated command coverage tables to mark endpoints implemented (including icon).
Tests & tooling
docs/TESTING.md, .cspell/dicts/project.txt
Added testing guidance about asserting raw text vs colored output and deriving Debug for test-only cases; added PRRT to project spell-check dictionary.
Tests
src/api/team.rs, src/cmd/team/*.rs (new modules)
Added unit tests covering response parsing, JSON serialization output, file writing for icon, and mock API error propagation.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as "CLI (bl team add/update/delete)"
  participant Client as "BacklogClient"
  participant Server as "Backlog API (HTTP)"
  participant Printer as "Stdout"

  CLI->>Client: call create/update/delete_team(params)
  Client->>Server: HTTP POST/PATCH/DELETE /api/v2/teams...
  Server-->>Client: JSON Team response
  Client-->>CLI: returns Team
  alt json flag
    CLI->>Printer: print pretty JSON
  else text flag
    CLI->>Printer: print format_team_row(Team)
  end
Loading
sequenceDiagram
  participant CLI as "CLI (bl team icon)"
  participant Client as "BacklogClient"
  participant Server as "Backlog API (HTTP)"
  participant FS as "Filesystem"
  participant Printer as "Stdout"

  CLI->>Client: call download_team_icon(team_id)
  Client->>Server: HTTP GET /api/v2/teams/{id}/icon
  Server-->>Client: bytes + filename (headers)
  Client-->>CLI: returns (bytes, filename)
  CLI->>FS: write bytes to path (derived from output or filename)
  FS-->>CLI: success
  CLI->>Printer: print saved path and byte count
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.88% 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 clearly and concisely summarizes the primary change: adding four new team management commands (add, update, delete, icon) to the CLI.
Description check ✅ Passed The description is well-structured and directly related to the changeset, including a clear summary, reason, specific changes, and notes about testing approach.
Linked Issues check ✅ Passed All requirements from issue #56 are implemented: bl team add (POST), bl team update (PATCH), bl team delete (DELETE), and bl team icon (GET) commands with API methods, CLI wiring, tests, and documentation.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the four team management commands: API methods, command implementations, CLI wiring, tests, and documentation updates. The refactoring of format_team_row to mod.rs is a supporting change for code organization.

✏️ 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/56-team-add-update-delete

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 the remaining mutating bl team subcommands (add/update/delete) plus a team icon download command, wiring them through the CLI layer, API client layer, and user docs to complete the team-management feature set (Issue #56).

Changes:

  • Added bl team add, bl team update, bl team delete, and bl team icon CLI commands and clap wiring.
  • Implemented corresponding BacklogClient + BacklogApi methods for /teams create/update/delete and /teams/{id}/icon download.
  • Updated EN/JA command documentation and the command coverage tables.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/api/team.rs Adds create/update/delete/download icon endpoints for teams, plus httpmock tests.
src/api/mod.rs Extends BacklogApi trait and dispatch impl with team mutation + icon methods.
src/cmd/team/add.rs New command implementation + unit tests for team creation.
src/cmd/team/update.rs New command implementation + unit tests + try_new validation.
src/cmd/team/delete.rs New command implementation + unit tests for team deletion.
src/cmd/team/icon.rs New command implementation + unit tests for icon download/save behavior.
src/cmd/team/mod.rs Exposes the new team subcommands/Args.
src/main.rs Adds clap variants and runtime dispatch for the new bl team subcommands.
website/docs/commands.md Documents new commands + marks endpoints implemented in coverage table (EN).
website/i18n/ja/.../commands.md Documents new commands + marks endpoints implemented in coverage table (JA).
docs/TESTING.md Adds testing guidance for ANSI formatting and conditional Debug derivations.
.cspell/dicts/project.txt Adds PRRT to the project dictionary.

…to delete/update output

Addresses review comments: deduplication of format_team_row across add/list/delete/update, consistent member count in text output, and accurate Debug requirement explanation in TESTING.md
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 (1)
src/cmd/team/delete.rs (1)

1-105: Please keep team subcommands consolidated in a single team command file.

This repo’s established pattern is one consolidated resource file for subcommands (with *_with variants), so introducing separate delete.rs increases fragmentation versus existing convention.

Based on learnings: "In the backlog-cli repo 23prime/backlog-cli, sub-resource command files under src/cmd// ... should consolidate all subcommands ... into a single file per resource. Do not split each subcommand into its own file."

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

In `@src/cmd/team/delete.rs` around lines 1 - 105, This change adds a standalone
src/cmd/team/delete.rs file which fragments the team subcommands; consolidate
its contents into the existing team command file by moving TeamDeleteArgs, the
delete and delete_with functions (preserve signatures and use of
BacklogClient::from_config and BacklogApi::delete_team), and the unit tests into
the main team module (keeping references to format_team_row and serde_json usage
unchanged), then remove this delete.rs file and update module visibility/imports
as needed so tests and callers still compile.
🤖 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/team/update.rs`:
- Around line 22-24: The try_new validation currently allows members =
Some(vec![]) to pass when name is absent; update Args::try_new (the function
validating name and members) to treat an empty members vector as absent and
reject the call when there is no name and members is either None or Some(empty).
Concretely, modify the conditional that checks name.is_none() &&
members.is_none() to also consider members.as_ref().map(|v|
v.is_empty()).unwrap_or(true) (or equivalent) so that try_new bails with the
same error ("at least one of --name or --member must be provided") when name is
None and members is empty or missing.

---

Nitpick comments:
In `@src/cmd/team/delete.rs`:
- Around line 1-105: This change adds a standalone src/cmd/team/delete.rs file
which fragments the team subcommands; consolidate its contents into the existing
team command file by moving TeamDeleteArgs, the delete and delete_with functions
(preserve signatures and use of BacklogClient::from_config and
BacklogApi::delete_team), and the unit tests into the main team module (keeping
references to format_team_row and serde_json usage unchanged), then remove this
delete.rs file and update module visibility/imports as needed so tests and
callers still compile.
🪄 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: 56d0090e-ddfe-416f-8e4d-bd1245381aa6

📥 Commits

Reviewing files that changed from the base of the PR and between 70a58ba and 8a416e8.

📒 Files selected for processing (6)
  • docs/TESTING.md
  • src/cmd/team/add.rs
  • src/cmd/team/delete.rs
  • src/cmd/team/list.rs
  • src/cmd/team/mod.rs
  • src/cmd/team/update.rs
✅ Files skipped from review due to trivial changes (1)
  • docs/TESTING.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cmd/team/mod.rs
  • src/cmd/team/add.rs

…s absent

Addresses review comment: treat Some(vec![]) as equivalent to None for members validation
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.

🧹 Nitpick comments (2)
src/cmd/team/update.rs (2)

70-77: Assert outgoing team_id and form params in tests.

Current MockApi ignores request inputs, so regressions in "members[]" expansion or ID forwarding won’t be caught. Add assertions in the mock and expected params in tests.

Suggested test hardening
 struct MockApi {
     team: Option<Team>,
+    expected_team_id: u64,
+    expected_params: Vec<(String, String)>,
 }

 impl crate::api::BacklogApi for MockApi {
-    fn update_team(&self, _team_id: u64, _params: &[(String, String)]) -> anyhow::Result<Team> {
+    fn update_team(&self, team_id: u64, params: &[(String, String)]) -> anyhow::Result<Team> {
+        assert_eq!(team_id, self.expected_team_id);
+        assert_eq!(params, self.expected_params.as_slice());
         self.team.clone().ok_or_else(|| anyhow!("update failed"))
     }
 }

 #[test]
 fn update_with_text_output_succeeds() {
     let api = MockApi {
         team: Some(sample_team()),
+        expected_team_id: 1,
+        expected_params: vec![("name".to_string(), "dev-team".to_string())],
     };
     assert!(update_with(&args(false), &api).is_ok());
 }

Also applies to: 109-130

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

In `@src/cmd/team/update.rs` around lines 70 - 77, MockApi currently ignores the
inputs so tests won't catch regressions; change MockApi (struct and impl) so it
stores expected_team_id: u64 and expected_params: Option<Vec<(String,String)>>
(or similar) and update update_team(&self, team_id, params) to assert team_id ==
self.expected_team_id and that params contains the expected key/value pairs
(including exact "members[]" expansions and ID string values), returning the
cloned Team only if assertions pass (or Err otherwise); update the tests that
construct MockApi to set expected_team_id and expected_params to match the
test's expected "members[]" entries and other form fields so the mock verifies
ID forwarding and param expansion.

1-5: Consider aligning team command layout with the repo’s resource-file convention.

This PR places subcommands in separate files (add.rs, update.rs, delete.rs, icon.rs), but the established repo pattern is to keep subcommands together under one resource file for consistency and discoverability. Based on learnings: “In the backlog-cli repo 23prime/backlog-cli, sub-resource command files under src/cmd// should consolidate all subcommands (add, update, delete, reorder, etc.) and their *_with variants into a single file per resource.”

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

In `@src/cmd/team/update.rs` around lines 1 - 5, The team subcommands are split
across separate files (add.rs, update.rs, delete.rs, icon.rs) which deviates
from the repo convention of grouping all subcommands for a resource into a
single resource file; consolidate those separate subcommand modules into one
file (e.g., src/cmd/team.rs) so add, update, delete, icon and any *_with
variants live together, move the relevant functions (e.g., the handlers and
helper functions currently in update.rs) into that single file, update the
module exports and use sites to import from the consolidated module (ensure
symbols like format_team_row, BacklogApi/BacklogClient usages are preserved),
and remove the now-unnecessary separate subcommand files or re-export them from
the single resource file to maintain discoverability and consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/cmd/team/update.rs`:
- Around line 70-77: MockApi currently ignores the inputs so tests won't catch
regressions; change MockApi (struct and impl) so it stores expected_team_id: u64
and expected_params: Option<Vec<(String,String)>> (or similar) and update
update_team(&self, team_id, params) to assert team_id == self.expected_team_id
and that params contains the expected key/value pairs (including exact
"members[]" expansions and ID string values), returning the cloned Team only if
assertions pass (or Err otherwise); update the tests that construct MockApi to
set expected_team_id and expected_params to match the test's expected
"members[]" entries and other form fields so the mock verifies ID forwarding and
param expansion.
- Around line 1-5: The team subcommands are split across separate files (add.rs,
update.rs, delete.rs, icon.rs) which deviates from the repo convention of
grouping all subcommands for a resource into a single resource file; consolidate
those separate subcommand modules into one file (e.g., src/cmd/team.rs) so add,
update, delete, icon and any *_with variants live together, move the relevant
functions (e.g., the handlers and helper functions currently in update.rs) into
that single file, update the module exports and use sites to import from the
consolidated module (ensure symbols like format_team_row,
BacklogApi/BacklogClient usages are preserved), and remove the now-unnecessary
separate subcommand files or re-export them from the single resource file to
maintain discoverability and consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ebb409c4-d7f3-42ed-9204-c41ed75ed222

📥 Commits

Reviewing files that changed from the base of the PR and between 8a416e8 and 1906965.

📒 Files selected for processing (1)
  • src/cmd/team/update.rs

@23prime 23prime merged commit 3a36ba7 into main Mar 22, 2026
8 checks passed
@23prime 23prime deleted the feature/56-team-add-update-delete branch March 22, 2026 04:15
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: bl team add / update / delete

2 participants