feat: implement branch protection rules #2

Open
opened 2026-06-02 06:56:52 +00:00 by a-limasov · 0 comments
Owner

Context

Branch protection rules prevent direct pushes to protected branches, enforce code review,
and require CI to pass. Essential for any repository with a development workflow.

Endpoints to implement

Method Path Tool name Description
GET /repos/{owner}/{repo}/branch_protections list_branch_protections List all branch protection rules
POST /repos/{owner}/{repo}/branch_protections create_branch_protection Create a new rule
GET /repos/{owner}/{repo}/branch_protections/{name} get_branch_protection Get a specific rule
PATCH /repos/{owner}/{repo}/branch_protections/{name} edit_branch_protection Update a rule
DELETE /repos/{owner}/{repo}/branch_protections/{name} delete_branch_protection Delete a rule

Acceptance Criteria

  • list_branch_protections(owner, repo) returns all rules
  • create_branch_protection(owner, repo, branch_name, ...) creates rule; key params: required_approvals, enable_push, require_signed_commits
  • get_branch_protection(owner, repo, name) fetches single rule by branch name pattern
  • edit_branch_protection(owner, repo, name, ...) updates rule fields via PATCH
  • delete_branch_protection(owner, repo, name) removes rule, returns {"success": true}
  • Branch name in URL is URL-encoded via _b() helper

Technical Notes

  • Branch protection name field is the branch name pattern (e.g. main, release/*)
  • Key create/edit body fields: branch_name, enable_push, enable_push_whitelist,
    push_whitelist_usernames, required_approvals, enable_approvals_whitelist,
    approvals_whitelist_usernames, require_signed_commits, block_on_outdated_branch
  • Use _strip() to omit unset optional fields
## Context Branch protection rules prevent direct pushes to protected branches, enforce code review, and require CI to pass. Essential for any repository with a development workflow. ## Endpoints to implement | Method | Path | Tool name | Description | |--------|------|-----------|-------------| | GET | `/repos/{owner}/{repo}/branch_protections` | `list_branch_protections` | List all branch protection rules | | POST | `/repos/{owner}/{repo}/branch_protections` | `create_branch_protection` | Create a new rule | | GET | `/repos/{owner}/{repo}/branch_protections/{name}` | `get_branch_protection` | Get a specific rule | | PATCH | `/repos/{owner}/{repo}/branch_protections/{name}` | `edit_branch_protection` | Update a rule | | DELETE | `/repos/{owner}/{repo}/branch_protections/{name}` | `delete_branch_protection` | Delete a rule | ## Acceptance Criteria - [ ] `list_branch_protections(owner, repo)` returns all rules - [ ] `create_branch_protection(owner, repo, branch_name, ...)` creates rule; key params: `required_approvals`, `enable_push`, `require_signed_commits` - [ ] `get_branch_protection(owner, repo, name)` fetches single rule by branch name pattern - [ ] `edit_branch_protection(owner, repo, name, ...)` updates rule fields via PATCH - [ ] `delete_branch_protection(owner, repo, name)` removes rule, returns `{"success": true}` - [ ] Branch name in URL is URL-encoded via `_b()` helper ## Technical Notes - Branch protection `name` field is the branch name pattern (e.g. `main`, `release/*`) - Key `create`/`edit` body fields: `branch_name`, `enable_push`, `enable_push_whitelist`, `push_whitelist_usernames`, `required_approvals`, `enable_approvals_whitelist`, `approvals_whitelist_usernames`, `require_signed_commits`, `block_on_outdated_branch` - Use `_strip()` to omit unset optional fields
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: a-limasov/gitea-platform-mcp#2