FJ-30: Add fj repo branch-protection subcommands (list/view/create/edit/delete) #38

Merged
David merged 2 commits from feat/repo-branch-protection-FJ-30 into main 2026-06-06 16:16:17 +02:00
Owner

Summary

Implements FJ-30: adds fj repo branch-protection list|view|create|edit|delete to manage a repository's branch protection rules.

What changed

  • fj-core (crates/fj-core/src/repo.rs): thin async wrappers over the forgejo-api endpoints following the existing repo-op pattern: list_branch_protections, get_branch_protection, create_branch_protection, edit_branch_protection, delete_branch_protection. No clap/crossterm/fluent deps added, so the MCP-reuse contract still holds.
  • fj binary (crates/fj/src/repo.rs): new BranchProtectionSubcommand enum wired as RepoCommand::BranchProtection under the branch-protection literal (alias branch-protections), mirroring the LabelsSubcommand pattern. A flattened BranchProtectionFlags Args struct exposes every field of CreateBranchProtectionOption / EditBranchProtectionOption as long-form flags; list-valued fields accept repeated flags, and an unset flag maps to None so the API leaves it unchanged. list and view honor the global --json flag via a stable BranchProtectionJson projection (mirrors LabelJson).
  • localization (crates/fj/localization/en-US/messages.ftl): new msg-repo-branch_protection-* strings for the success/empty messages.

Rules are addressed by rule_name (the API path parameter). branch_name (deprecated by the API) is exposed on create only and defaults to the rule name when omitted.

Acceptance criteria

  • fj-core exposes list/get/create/edit/delete wrappers; cargo tree -p fj-client -p fj-core -e normal | grep -E 'clap|crossterm|fluent' stays empty
  • branch-protection list prints all rules; --json emits the projection structs
  • branch-protection view <rule_name> shows one rule; --json supported
  • branch-protection create accepts long-form flags covering every CreateBranchProtectionOption field
  • branch-protection edit <rule_name> accepts the same flags (all optional), sending only set fields
  • branch-protection delete <rule_name> removes the rule
  • New output strings have en-US .ftl entries

Verification

cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo build --all-targets, and cargo test all pass; the MCP-contract grep is empty. CLI help for the new subcommands renders correctly.

#FJ-30

## Summary Implements FJ-30: adds `fj repo branch-protection list|view|create|edit|delete` to manage a repository's branch protection rules. ## What changed - **fj-core** (`crates/fj-core/src/repo.rs`): thin async wrappers over the `forgejo-api` endpoints following the existing repo-op pattern: `list_branch_protections`, `get_branch_protection`, `create_branch_protection`, `edit_branch_protection`, `delete_branch_protection`. No clap/crossterm/fluent deps added, so the MCP-reuse contract still holds. - **fj binary** (`crates/fj/src/repo.rs`): new `BranchProtectionSubcommand` enum wired as `RepoCommand::BranchProtection` under the `branch-protection` literal (alias `branch-protections`), mirroring the `LabelsSubcommand` pattern. A flattened `BranchProtectionFlags` Args struct exposes every field of `CreateBranchProtectionOption` / `EditBranchProtectionOption` as long-form flags; list-valued fields accept repeated flags, and an unset flag maps to `None` so the API leaves it unchanged. `list` and `view` honor the global `--json` flag via a stable `BranchProtectionJson` projection (mirrors `LabelJson`). - **localization** (`crates/fj/localization/en-US/messages.ftl`): new `msg-repo-branch_protection-*` strings for the success/empty messages. Rules are addressed by `rule_name` (the API path parameter). `branch_name` (deprecated by the API) is exposed on `create` only and defaults to the rule name when omitted. ## Acceptance criteria - [x] fj-core exposes list/get/create/edit/delete wrappers; `cargo tree -p fj-client -p fj-core -e normal | grep -E 'clap|crossterm|fluent'` stays empty - [x] `branch-protection list` prints all rules; `--json` emits the projection structs - [x] `branch-protection view <rule_name>` shows one rule; `--json` supported - [x] `branch-protection create` accepts long-form flags covering every `CreateBranchProtectionOption` field - [x] `branch-protection edit <rule_name>` accepts the same flags (all optional), sending only set fields - [x] `branch-protection delete <rule_name>` removes the rule - [x] New output strings have en-US .ftl entries ## Verification `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `cargo build --all-targets`, and `cargo test` all pass; the MCP-contract grep is empty. CLI help for the new subcommands renders correctly. #FJ-30
feat(repo): add branch-protection subcommands (list/view/create/edit/delete)
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 54s
3cc32823fa
Add `fj repo branch-protection list|view|create|edit|delete` to manage a repository's branch protection rules. The API/domain wrappers live in fj-core (list/get/create/edit/delete) so the planned Forgejo MCP can reuse them; the clap surface, rendering, and localization stay in the fj binary. The MCP-reuse contract holds: fj-client and fj-core pull in no clap/crossterm/fluent.

Rules are addressed by their rule name (the API path parameter). `create` and `edit` expose every field of CreateBranchProtectionOption / EditBranchProtectionOption as long-form flags; list-valued fields accept repeated flags and an unset flag maps to None so the API leaves it unchanged. `list` and `view` honor the global --json flag via a stable BranchProtectionJson projection, mirroring the existing LabelJson pattern. New user-facing strings are added to en-US messages.ftl.

#FJ-30
Merge branch 'main' into feat/repo-branch-protection-FJ-30
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 37s
Create release / Create release from merged PR (pull_request) Has been skipped
1de9847bfe
Resolves conflicts with the collaborator (#37) and webhook (#36) subcommands: union of imports and op functions in fj-core repo.rs, all three ftl message blocks kept, and the branch-protection RepoCommand variant, match arm, subcommand enum, JSON projection, and helpers restored alongside the collaborator and webhook code in the binary.

#FJ-30
David merged commit ca9bba1b13 into main 2026-06-06 16:16:17 +02:00
David deleted branch feat/repo-branch-protection-FJ-30 2026-06-06 16:16:17 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pandoras-box/forgejo-cli!38
No description provided.