Documentation
¶
Overview ¶
Package branches implements MCP tool handlers for GitLab branch operations including create, list, get, delete, and branch protection management. It wraps the Branches and ProtectedBranches services from client-go v2.
Index ¶
- func Delete(ctx context.Context, client *gitlabclient.Client, input DeleteInput) error
- func DeleteMerged(ctx context.Context, client *gitlabclient.Client, input DeleteMergedInput) error
- func FormatListMarkdown(out ListOutput) string
- func FormatOutputMarkdown(br Output) string
- func FormatProtectedListMarkdown(out ProtectedListOutput) string
- func FormatProtectedMarkdown(pb ProtectedOutput) string
- func RegisterTools(server *mcp.Server, client *gitlabclient.Client)
- type CreateInput
- type DeleteInput
- type DeleteMergedInput
- type GetInput
- type ListInput
- type ListOutput
- type Output
- type ProtectInput
- type ProtectedGetInput
- type ProtectedListInput
- type ProtectedListOutput
- type ProtectedOutput
- func Protect(ctx context.Context, client *gitlabclient.Client, input ProtectInput) (ProtectedOutput, error)
- func ProtectedGet(ctx context.Context, client *gitlabclient.Client, input ProtectedGetInput) (ProtectedOutput, error)
- func ProtectedToOutput(b *gl.ProtectedBranch) ProtectedOutput
- func ProtectedUpdate(ctx context.Context, client *gitlabclient.Client, input ProtectedUpdateInput) (ProtectedOutput, error)
- type ProtectedUpdateInput
- type UnprotectInput
- type UnprotectOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(ctx context.Context, client *gitlabclient.Client, input DeleteInput) error
Delete deletes a branch from a GitLab project.
func DeleteMerged ¶
func DeleteMerged(ctx context.Context, client *gitlabclient.Client, input DeleteMergedInput) error
DeleteMerged deletes all branches that have been merged into the default branch. The default branch and protected branches are never deleted.
func FormatListMarkdown ¶
func FormatListMarkdown(out ListOutput) string
FormatListMarkdown renders a list of branches as a Markdown table.
func FormatOutputMarkdown ¶
FormatOutputMarkdown renders a single branch as a Markdown summary.
func FormatProtectedListMarkdown ¶
func FormatProtectedListMarkdown(out ProtectedListOutput) string
FormatProtectedListMarkdown renders a list of protected branches as a Markdown table.
func FormatProtectedMarkdown ¶
func FormatProtectedMarkdown(pb ProtectedOutput) string
FormatProtectedMarkdown renders a single protected branch as Markdown.
func RegisterTools ¶
func RegisterTools(server *mcp.Server, client *gitlabclient.Client)
RegisterTools registers all branch tools on the given MCP server.
Types ¶
type CreateInput ¶
type CreateInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"New branch name (param 'branch_name' not 'branch' or 'name'),required"`
Ref string `json:"ref" jsonschema:"Branch name, tag, or commit SHA to create from,required"`
}
CreateInput defines parameters for creating a new branch.
type DeleteInput ¶
type DeleteInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Branch name to delete,required"`
}
DeleteInput defines parameters for deleting a branch.
type DeleteMergedInput ¶
type DeleteMergedInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
}
DeleteMergedInput defines parameters for deleting all merged branches in a project.
type GetInput ¶
type GetInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Branch name to retrieve (param 'branch_name' not 'branch'),required"`
}
GetInput defines parameters for retrieving a single branch.
type ListInput ¶
type ListInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
Search string `json:"search,omitempty" jsonschema:"Filter branches by name (substring match)"`
toolutil.PaginationInput
}
ListInput defines parameters for listing branches.
type ListOutput ¶
type ListOutput struct {
toolutil.HintableOutput
Branches []Output `json:"branches"`
Pagination toolutil.PaginationOutput `json:"pagination"`
}
ListOutput holds a paginated list of branches.
func List ¶
func List(ctx context.Context, client *gitlabclient.Client, input ListInput) (ListOutput, error)
List retrieves a paginated list of branches for the specified GitLab project. An optional search filter restricts results by branch name substring.
type Output ¶
type Output struct {
toolutil.HintableOutput
Name string `json:"name"`
Merged bool `json:"merged"`
Protected bool `json:"protected"`
Default bool `json:"default"`
WebURL string `json:"web_url"`
CommitID string `json:"commit_id"`
CanPush bool `json:"can_push"`
DevelopersCanPush bool `json:"developers_can_push"`
DevelopersCanMerge bool `json:"developers_can_merge"`
}
Output represents a Git branch.
func Create ¶
func Create(ctx context.Context, client *gitlabclient.Client, input CreateInput) (Output, error)
Create creates a new branch in the specified GitLab project from the given ref (branch, tag, or commit SHA). Returns the created branch details or an error if the ref does not exist or the branch already exists.
type ProtectInput ¶
type ProtectInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Branch name or wildcard (e.g. 'main' or 'release/*'),required"`
PushAccessLevel int `json:"push_access_level,omitempty" jsonschema:"Access level for push (0=No access 30=Developer 40=Maintainer)"`
MergeAccessLevel int `json:"merge_access_level,omitempty" jsonschema:"Access level for merge (0=No access 30=Developer 40=Maintainer)"`
AllowForcePush *bool `json:"allow_force_push,omitempty" jsonschema:"Allow force push to this branch"`
CodeOwnerApprovalRequired *bool `json:"code_owner_approval_required,omitempty" jsonschema:"Require CODEOWNERS approval for changes to matching files"`
}
ProtectInput defines parameters for protecting a branch.
type ProtectedGetInput ¶
type ProtectedGetInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Name of the protected branch,required"`
}
ProtectedGetInput defines parameters for retrieving a single protected branch.
type ProtectedListInput ¶
type ProtectedListInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
toolutil.PaginationInput
}
ProtectedListInput defines parameters for listing protected branches.
type ProtectedListOutput ¶
type ProtectedListOutput struct {
toolutil.HintableOutput
Branches []ProtectedOutput `json:"branches"`
Pagination toolutil.PaginationOutput `json:"pagination"`
}
ProtectedListOutput holds the list of protected branches.
func ProtectedList ¶
func ProtectedList(ctx context.Context, client *gitlabclient.Client, input ProtectedListInput) (ProtectedListOutput, error)
ProtectedList retrieves a paginated list of protected branches for the specified GitLab project. Pagination parameters are forwarded to the API.
type ProtectedOutput ¶
type ProtectedOutput struct {
toolutil.HintableOutput
ID int64 `json:"id"`
Name string `json:"name"`
PushAccessLevel int `json:"push_access_level"`
MergeAccessLevel int `json:"merge_access_level"`
AllowForcePush bool `json:"allow_force_push"`
CodeOwnerApprovalRequired bool `json:"code_owner_approval_required"`
AlreadyProtected bool `json:"already_protected,omitempty"`
}
ProtectedOutput represents a protected branch.
func Protect ¶
func Protect(ctx context.Context, client *gitlabclient.Client, input ProtectInput) (ProtectedOutput, error)
Protect protects a branch in the specified GitLab project by calling the Protected Branches API. It configures push and merge access levels and optionally enables force push. Returns an error if the API call fails.
func ProtectedGet ¶
func ProtectedGet(ctx context.Context, client *gitlabclient.Client, input ProtectedGetInput) (ProtectedOutput, error)
ProtectedGet retrieves a single protected branch by name.
func ProtectedToOutput ¶
func ProtectedToOutput(b *gl.ProtectedBranch) ProtectedOutput
ProtectedToOutput converts a GitLab API gl.ProtectedBranch to the MCP tool output format, extracting push and merge access levels from the first entry of each access level slice.
func ProtectedUpdate ¶
func ProtectedUpdate(ctx context.Context, client *gitlabclient.Client, input ProtectedUpdateInput) (ProtectedOutput, error)
ProtectedUpdate updates settings on an existing protected branch.
type ProtectedUpdateInput ¶
type ProtectedUpdateInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Name of the protected branch,required"`
AllowForcePush *bool `json:"allow_force_push,omitempty" jsonschema:"Allow force push to this branch"`
CodeOwnerApprovalRequired *bool `json:"code_owner_approval_required,omitempty" jsonschema:"Require CODEOWNERS approval"`
}
ProtectedUpdateInput defines parameters for updating a protected branch's settings.
type UnprotectInput ¶
type UnprotectInput struct {
ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
BranchName string `json:"branch_name" jsonschema:"Name of the protected branch to remove,required"`
}
UnprotectInput defines parameters for unprotecting a branch.
type UnprotectOutput ¶
type UnprotectOutput struct {
toolutil.HintableOutput
Status string `json:"status"`
Message string `json:"message"`
}
UnprotectOutput holds the result of an unprotect operation.
func Unprotect ¶
func Unprotect(ctx context.Context, client *gitlabclient.Client, input UnprotectInput) (UnprotectOutput, error)
Unprotect removes protection from a branch in the specified GitLab project. The operation is idempotent: if the branch is not protected, it returns success with an informational message instead of an error.