Skip to content

feat(repositories): add delete_branch tool#2790

Open
huzaifa678 wants to merge 1 commit into
github:mainfrom
huzaifa678:add-delete-branch-tool
Open

feat(repositories): add delete_branch tool#2790
huzaifa678 wants to merge 1 commit into
github:mainfrom
huzaifa678:add-delete-branch-tool

Conversation

@huzaifa678

Copy link
Copy Markdown

Description

Adds a delete_branch tool to the repositories toolset, resolving #1476.

The repo already exposes create_branch and list_branches but had no way to delete a branch. This fills that gap, following the existing create_branch implementation pattern.

Guardrail

As requested in the issue, the tool will not delete a protected branch. It fetches the branch first and, if protected is true, returns a tool error rather than attempting the deletion — giving the model actionable feedback.

Behavior

Aspect Value
Tool name delete_branch
Required params owner, repo, branch
ReadOnlyHint false
Scope repo

Flow:

  1. GET /repos/{owner}/{repo}/branches/{branch} → check protection status
  2. If protected → return error, do not delete
  3. Otherwise DELETE /repos/{owner}/{repo}/git/refs/heads/{branch}

Testing

Test_DeleteBranch covers:

  • successful deletion of an unprotected branch
  • refusal to delete a protected branch
  • branch not found
  • deletion API failure

Verified locally:

  • go test ./... — pass
  • golangci-lint run — 0 issues
  • script/generate-docs — README updated
  • UPDATE_TOOLSNAPS=true go test ./... — snapshot committed

Checklist

  • Tests added
  • script/lint passes
  • Toolsnap committed (pkg/github/__toolsnaps__/delete_branch.snap)
  • README regenerated via script/generate-docs
  • Change is focused on a single tool

Closes #1476

The repositories toolset exposes create_branch and list_branches but
provides no way to delete a branch. This adds a delete_branch tool that
fills that gap, following the existing create_branch implementation.

As a guardrail, the tool fetches the branch first and refuses to delete
protected branches, returning a clear error to the model instead of
attempting the deletion. It requires owner, repo, and branch, is scoped
to `repo`, and is annotated as a non-read-only operation.

Tests cover successful deletion, protected-branch refusal, branch not
found, and deletion failure.

Closes github#1476
@huzaifa678 huzaifa678 requested a review from a team as a code owner June 28, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant