mrapprovals

package
v2.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mrapprovals implements MCP tools for GitLab merge request approval operations.

The package wraps the GitLab Merge request approvals API:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionSpecs

func ActionSpecs(client *gitlabclient.Client) []toolutil.ActionSpec

ActionSpecs returns canonical specs for merge request approval actions.

func DeleteRule

func DeleteRule(ctx context.Context, client *gitlabclient.Client, input DeleteRuleInput) error

DeleteRule removes an approval rule from a merge request.

func FormatConfigMarkdown

func FormatConfigMarkdown(c ConfigOutput) string

FormatConfigMarkdown renders the MR approval configuration as Markdown.

func FormatRuleMarkdown

func FormatRuleMarkdown(r RuleOutput) string

FormatRuleMarkdown renders a single MR approval rule as Markdown.

func FormatRulesMarkdown

func FormatRulesMarkdown(out RulesOutput) string

FormatRulesMarkdown renders a list of MR approval rules as Markdown.

func FormatStateMarkdown

func FormatStateMarkdown(s StateOutput) string

FormatStateMarkdown renders the MR approval state as Markdown.

func Reset

func Reset(ctx context.Context, client *gitlabclient.Client, input ResetInput) error

Reset clears all existing approvals on a merge request.

Types

type BasicUserOutput added in v2.3.0

type BasicUserOutput struct {
	ID        int64  `json:"id"`
	Username  string `json:"username"`
	Name      string `json:"name"`
	State     string `json:"state,omitempty"`
	AvatarURL string `json:"avatar_url,omitempty"`
	WebURL    string `json:"web_url,omitempty"`
}

BasicUserOutput is the documented reference subset of the compact user object embedded in approval payloads (suggested_approvers, eligible_approvers, users, and the approved_by list on approval rules).

Documented reference subset per doc/api/merge_request_approvals.md: the rule users[]/eligible_approvers[]/approved_by[] examples surface only id, name, username, state, avatar_url, and web_url. gl.BasicUser additionally carries created_at, which the documented reference object omits; it is therefore not projected here.

type ConfigInput

type ConfigInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MRIID     int64                `json:"merge_request_iid"     jsonschema:"Merge request internal ID,required"`
}

ConfigInput defines parameters for getting approval configuration.

type ConfigOutput

type ConfigOutput struct {
	toolutil.HintableOutput
	ID                             int64                              `json:"id"`
	IID                            int64                              `json:"iid"`
	ProjectID                      int64                              `json:"project_id"`
	Title                          string                             `json:"title"`
	Description                    string                             `json:"description,omitempty"`
	State                          string                             `json:"state"`
	CreatedAt                      string                             `json:"created_at,omitempty"`
	UpdatedAt                      string                             `json:"updated_at,omitempty"`
	MergeStatus                    string                             `json:"merge_status,omitempty"`
	Approved                       bool                               `json:"approved"`
	ApprovalsRequired              int64                              `json:"approvals_required" tier:"premium"`
	ApprovalsLeft                  int64                              `json:"approvals_left" tier:"premium"`
	ApprovalsBeforeMerge           int64                              `json:"approvals_before_merge" tier:"premium"`
	RequirePasswordToApprove       bool                               `json:"require_password_to_approve" tier:"premium"`
	HasApprovalRules               bool                               `json:"has_approval_rules" tier:"premium"`
	UserHasApproved                bool                               `json:"user_has_approved"`
	UserCanApprove                 bool                               `json:"user_can_approve"`
	MergeRequestApproversAvailable bool                               `json:"merge_request_approvers_available" tier:"premium"`
	MultipleApprovalRulesAvailable bool                               `json:"multiple_approval_rules_available" tier:"premium"`
	ApprovedBy                     []*MergeRequestApproverUserOutput  `json:"approved_by,omitempty"`
	SuggestedApprovers             []*BasicUserOutput                 `json:"suggested_approvers,omitempty" tier:"premium"`
	Approvers                      []*MergeRequestApproverUserOutput  `json:"approvers,omitempty" tier:"premium"`
	ApproverGroups                 []*MergeRequestApproverGroupOutput `json:"approver_groups,omitempty" tier:"premium"`
	ApprovalRulesLeft              []RuleOutput                       `json:"approval_rules_left,omitempty" tier:"premium"`
}

ConfigOutput holds the approval configuration for a merge request. It mirrors gl.MergeRequestApprovals, surfacing every SDK field including the full approver/suggested-approver/approver-group objects and the per-rule approval_rules_left list on their canonical keys.

func Config

func Config(ctx context.Context, client *gitlabclient.Client, input ConfigInput) (ConfigOutput, error)

Config retrieves the approval configuration (approvals required, current approvers, suggested approvers) for a merge request.

type CreateRuleInput

type CreateRuleInput struct {
	ProjectID             toolutil.StringOrInt `json:"project_id"               jsonschema:"Project ID or URL-encoded path,required"`
	MRIID                 int64                `json:"merge_request_iid"                   jsonschema:"Merge request internal ID,required"`
	Name                  string               `json:"name"                     jsonschema:"Rule name,required"`
	ApprovalsRequired     int64                `json:"approvals_required"       jsonschema:"Number of approvals required,required"`
	ApprovalProjectRuleID int64                `json:"approval_project_rule_id" jsonschema:"Project-level approval rule ID to inherit from"`
	UserIDs               []int64              `json:"user_ids"                 jsonschema:"User IDs eligible to approve"`
	GroupIDs              []int64              `json:"group_ids"                jsonschema:"Group IDs eligible to approve"`
}

CreateRuleInput defines parameters for creating an MR approval rule.

type DeleteRuleInput

type DeleteRuleInput struct {
	ProjectID      toolutil.StringOrInt `json:"project_id"       jsonschema:"Project ID or URL-encoded path,required"`
	MRIID          int64                `json:"merge_request_iid"           jsonschema:"Merge request internal ID,required"`
	ApprovalRuleID int64                `json:"approval_rule_id" jsonschema:"Approval rule ID,required"`
}

DeleteRuleInput defines parameters for deleting an MR approval rule.

type GroupOutput added in v2.3.0

type GroupOutput struct {
	ID                   int64  `json:"id"`
	Name                 string `json:"name"`
	Path                 string `json:"path"`
	FullPath             string `json:"full_path,omitempty"`
	FullName             string `json:"full_name,omitempty"`
	Description          string `json:"description,omitempty"`
	Visibility           string `json:"visibility,omitempty"`
	WebURL               string `json:"web_url,omitempty"`
	AvatarURL            string `json:"avatar_url,omitempty"`
	ParentID             int64  `json:"parent_id,omitempty"`
	RequestAccessEnabled bool   `json:"request_access_enabled"`
	LFSEnabled           bool   `json:"lfs_enabled"`
}

GroupOutput is the documented reference subset of the group object embedded in an approval rule's groups list.

Documented reference subset per doc/api/merge_request_approvals.md: the rule groups[] example surfaces id, name, path, description, visibility, lfs_enabled, avatar_url, web_url, request_access_enabled, full_name, full_path, and parent_id (the ldap_cn/ldap_access LDAP extras are EE-only and the large nested statistics/deprecated project lists carried by gl.Group are not part of the documented reference object). gl.Group additionally carries created_at, which the documented reference object omits; it is therefore not projected here.

type MergeRequestApproverGroupOutput added in v2.3.0

type MergeRequestApproverGroupOutput struct {
	Group MergeRequestApproverNestedGroupOutput `json:"group"`
}

MergeRequestApproverGroupOutput mirrors gl.MergeRequestApproverGroup, the wrapper object carrying a single nested approver group.

type MergeRequestApproverNestedGroupOutput added in v2.3.0

type MergeRequestApproverNestedGroupOutput struct {
	ID                   int64  `json:"id"`
	Name                 string `json:"name"`
	Path                 string `json:"path"`
	Description          string `json:"description,omitempty"`
	Visibility           string `json:"visibility,omitempty"`
	AvatarURL            string `json:"avatar_url,omitempty"`
	WebURL               string `json:"web_url,omitempty"`
	FullName             string `json:"full_name,omitempty"`
	FullPath             string `json:"full_path,omitempty"`
	LFSEnabled           bool   `json:"lfs_enabled"`
	RequestAccessEnabled bool   `json:"request_access_enabled"`
}

MergeRequestApproverNestedGroupOutput mirrors gl.MergeRequestApproverNestedGroup, the group object embedded in the approver_groups list of a merge-request approval configuration.

type MergeRequestApproverUserOutput added in v2.3.0

type MergeRequestApproverUserOutput struct {
	User       *BasicUserOutput `json:"user,omitempty"`
	ApprovedAt string           `json:"approved_at,omitempty"`
}

MergeRequestApproverUserOutput mirrors gl.MergeRequestApproverUser, pairing an approver's user object with the timestamp at which they approved. Its nested user object is the documented reference subset BasicUserOutput per doc/api/merge_request_approvals.md (the approved_by[].user example).

type ProjectApprovalRuleOutput added in v2.3.0

type ProjectApprovalRuleOutput struct {
	ID                            int64                    `json:"id"`
	Name                          string                   `json:"name"`
	RuleType                      string                   `json:"rule_type,omitempty"`
	ReportType                    string                   `json:"report_type,omitempty"`
	EligibleApprovers             []*BasicUserOutput       `json:"eligible_approvers,omitempty"`
	ApprovalsRequired             int64                    `json:"approvals_required"`
	Users                         []*BasicUserOutput       `json:"users,omitempty"`
	Groups                        []*GroupOutput           `json:"groups,omitempty"`
	ContainsHiddenGroups          bool                     `json:"contains_hidden_groups"`
	ProtectedBranches             []*ProtectedBranchOutput `json:"protected_branches,omitempty"`
	AppliesToAllProtectedBranches bool                     `json:"applies_to_all_protected_branches"`
}

ProjectApprovalRuleOutput mirrors gl.ProjectApprovalRule, the project-level approval rule referenced as the source_rule of a merge-request approval rule.

The documented examples in doc/api/merge_request_approvals.md always render source_rule as null, so the doc provides no reference sub-field shape to trim against. This SDK-modeled superset is retained additively (version drift → keep) so instances that populate source_rule do not lose data. Its nested user lists reuse the documented reference subset BasicUserOutput and its groups reuse the documented reference subset GroupOutput.

type ProtectedBranchOutput added in v2.3.0

type ProtectedBranchOutput struct {
	ID                        int64  `json:"id"`
	Name                      string `json:"name"`
	AllowForcePush            bool   `json:"allow_force_push"`
	CodeOwnerApprovalRequired bool   `json:"code_owner_approval_required"`
}

ProtectedBranchOutput mirrors the identifying fields of gl.ProtectedBranch as embedded in a project approval rule's protected_branches list.

type ResetInput

type ResetInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MRIID     int64                `json:"merge_request_iid"     jsonschema:"Merge request internal ID,required"`
}

ResetInput defines parameters for resetting approvals on a merge request.

type RuleOutput

type RuleOutput struct {
	toolutil.HintableOutput
	ID                   int64                      `json:"id"`
	Name                 string                     `json:"name"`
	RuleType             string                     `json:"rule_type"`
	ReportType           string                     `json:"report_type,omitempty"`
	Section              string                     `json:"section,omitempty"`
	ApprovalsRequired    int                        `json:"approvals_required"`
	Approved             bool                       `json:"approved"`
	ContainsHiddenGroups bool                       `json:"contains_hidden_groups,omitempty"`
	Overridden           bool                       `json:"overridden,omitempty"`
	ApprovedBy           []*BasicUserOutput         `json:"approved_by,omitempty"`
	EligibleApprovers    []*BasicUserOutput         `json:"eligible_approvers,omitempty"`
	Users                []*BasicUserOutput         `json:"users,omitempty"`
	Groups               []*GroupOutput             `json:"groups,omitempty"`
	SourceRule           *ProjectApprovalRuleOutput `json:"source_rule,omitempty"`
}

RuleOutput represents a single approval rule for a merge request. It mirrors gl.MergeRequestApprovalRule, surfacing the full approver/eligible/user/group objects and the project-level source rule on their canonical keys.

func CreateRule

func CreateRule(ctx context.Context, client *gitlabclient.Client, input CreateRuleInput) (RuleOutput, error)

CreateRule creates a new approval rule on a merge request.

func RuleToOutput

func RuleToOutput(r *gl.MergeRequestApprovalRule) RuleOutput

RuleToOutput converts a client-go MergeRequestApprovalRule to the MCP output representation, surfacing the full approver/eligible/user/group objects and the project-level source rule on their canonical keys.

func UpdateRule

func UpdateRule(ctx context.Context, client *gitlabclient.Client, input UpdateRuleInput) (RuleOutput, error)

UpdateRule updates an existing approval rule on a merge request.

type RulesInput

type RulesInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MRIID     int64                `json:"merge_request_iid"     jsonschema:"Merge request internal ID,required"`
}

RulesInput defines parameters for listing the approval rules of a merge request.

type RulesOutput

type RulesOutput struct {
	toolutil.HintableOutput
	Rules []RuleOutput `json:"rules"`
}

RulesOutput holds the list of approval rules for a merge request.

func Rules

func Rules(ctx context.Context, client *gitlabclient.Client, input RulesInput) (RulesOutput, error)

Rules lists the approval rules configured for a merge request.

type StateInput

type StateInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MRIID     int64                `json:"merge_request_iid"     jsonschema:"Merge request internal ID,required"`
}

StateInput defines parameters for retrieving the approval state of a merge request.

type StateOutput

type StateOutput struct {
	toolutil.HintableOutput
	ApprovalRulesOverwritten bool         `json:"approval_rules_overwritten"`
	Rules                    []RuleOutput `json:"rules"`
}

StateOutput holds the overall approval state for a merge request, including whether rules have been overridden and the list of applicable rules.

func State

func State(ctx context.Context, client *gitlabclient.Client, input StateInput) (StateOutput, error)

State retrieves the approval state of a merge request, including whether approval rules have been overridden and the list of rules with their current approval status.

type UpdateRuleInput

type UpdateRuleInput struct {
	ProjectID         toolutil.StringOrInt `json:"project_id"         jsonschema:"Project ID or URL-encoded path,required"`
	MRIID             int64                `json:"merge_request_iid"             jsonschema:"Merge request internal ID,required"`
	ApprovalRuleID    int64                `json:"approval_rule_id"   jsonschema:"Approval rule ID,required"`
	Name              string               `json:"name"               jsonschema:"Rule name"`
	ApprovalsRequired *int64               `json:"approvals_required" jsonschema:"Number of approvals required"`
	UserIDs           []int64              `json:"user_ids"           jsonschema:"User IDs eligible to approve"`
	GroupIDs          []int64              `json:"group_ids"          jsonschema:"Group IDs eligible to approve"`
}

UpdateRuleInput defines parameters for updating an MR approval rule.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL