Help us shape the future of Go! Take the 2026 Go Developer Survey

mrcontextcommits

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mrcontextcommits implements MCP tools for GitLab merge request context commit operations.

The package wraps the GitLab Merge requests API context commit endpoints:

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 context commit actions.

func Delete

func Delete(ctx context.Context, client *gitlabclient.Client, input DeleteInput) error

Delete removes context commits from a merge request.

func FormatCreateMarkdown added in v3.1.0

func FormatCreateMarkdown(out CreateOutput) *mcp.CallToolResult

FormatCreateMarkdown renders the commits create_context_commits pinned as the same table the list is rendered as.

func FormatCreateMarkdownString added in v3.1.0

func FormatCreateMarkdownString(out CreateOutput) string

FormatCreateMarkdownString renders the pinned commits as Markdown. The answer is every commit pinned rather than a page, so the table carries no page and the heading counts what is shown.

func FormatListMarkdown

func FormatListMarkdown(out ListOutput) *mcp.CallToolResult

FormatListMarkdown renders the context commits attached to a merge request as a Markdown table: a collection of objects that share columns.

func FormatListMarkdownString added in v3.1.0

func FormatListMarkdownString(out ListOutput) string

FormatListMarkdownString renders the context commit list as Markdown.

Types

type CommitAuthor added in v3.1.0

type CommitAuthor struct {
	toolutil.UserBasicOutput
	Path       string `json:"path,omitempty"`
	ShowStatus bool   `json:"show_status"`
}

CommitAuthor is the GitLab account a listed context commit's author email belongs to, with the keys of lib/api/entities/user_path.rb: the basic user, the path of the user's profile, and show_status. GitLab sends null for an email no confirmed account holds, since Commit#lazy_author looks the author up with `User.by_any_email(emails, confirmed: true)`, and the key is then absent here.

None of the entity's conditional keys reaches this route: avatar_path and custom_attributes wait on presenter options the route does not pass, and status_tooltip_html and availability on a status association that lookup does not preload. The same unloaded association is why show_status is false on every author this route sends; it is published because GitLab sends it.

type CommitItem

type CommitItem struct {
	ID                string              `json:"id"`
	ShortID           string              `json:"short_id"`
	Title             string              `json:"title"`
	Message           string              `json:"message,omitempty"`
	AuthorName        string              `json:"author_name"`
	AuthorEmail       string              `json:"author_email"`
	AuthoredDate      string              `json:"authored_date,omitempty"`
	CommitterName     string              `json:"committer_name,omitempty"`
	CommitterEmail    string              `json:"committer_email,omitempty"`
	CommittedDate     string              `json:"committed_date,omitempty"`
	CreatedAt         string              `json:"created_at,omitempty"`
	ParentIDs         []string            `json:"parent_ids,omitempty"`
	Trailers          map[string]string   `json:"trailers,omitempty"`
	ExtendedTrailers  map[string][]string `json:"extended_trailers,omitempty"`
	WebURL            string              `json:"web_url,omitempty"`
	Author            *CommitAuthor       `json:"author,omitempty"`
	AuthorGravatarURL string              `json:"author_gravatar_url,omitempty"`
	DescriptionHTML   string              `json:"description_html,omitempty"`
	TitleHTML         string              `json:"title_html,omitempty"`
}

CommitItem is one context commit, the keys of lib/api/entities/commit.rb. create_context_commits answers with that entity; the list answers with lib/api/entities/commit_with_link.rb, which extends it.

A context commit read back from the list is rebuilt from the row GitLab stored when it was pinned, and that row keeps no parents (MergeRequests::AddContextService drops them), so parent_ids arrives on the answer to create_context_commits and is empty on the list.

extended_trailers maps each trailer to the list of its values, which is how Gitlab::Git::Commit#parse_commit_trailers builds it and how the entity documents it.

Author, AuthorGravatarURL, DescriptionHTML and TitleHTML are keys lib/api/entities/commit_with_link.rb adds, so the list fills them and the answer to create_context_commits never does. The list route presents `with: Entities::CommitWithLink, type: :full, request: merge_request` (lib/api/merge_requests.rb), and until GitLab 19.5 its desc annotated Entities::Commit, which is why GitLab's generated reference knew none of them; the record R-PATH reads holds the route under CommitWithLink since it was taken from 19.5.0. The rest of what CommitWithLink adds is left out on purpose, each declared in cmd/audit_1to1/internal/paths: commit_url is web_url again and commit_path is its path, and signature_html, prev_commit_id, next_commit_id and pipeline_status_path are null on every commit of this route. The last three read presenter options the route does not pass, and signature_html renders only for a commit with a signature, which a context commit rebuilt from its stored row never has: Commit#raw_signature_type reads it off the Gitaly commit, and MergeRequestContextCommit#to_commit builds the commit from a hash of the row, which keeps no signature.

author_gravatar_url is the instance's Gravatar image for author_email (GravatarService, which the instance can point elsewhere or turn off, and then it is null), the one picture of an author no account holds.

type CreateInput

type CreateInput struct {
	ProjectID    toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MergeRequest int64                `json:"merge_request_iid"     jsonschema:"Merge request IID,required"`
	Commits      []string             `json:"commits"    jsonschema:"List of commit SHAs to add as context,required"`
}

CreateInput is the input for creating MR context commits.

type CreateOutput added in v3.1.0

type CreateOutput struct {
	toolutil.HintableOutput
	Commits []CommitItem `json:"commits"`
}

CreateOutput is the answer to create_context_commits: the commits it pinned, in the order GitLab answered with them.

It is not ListOutput, because the route is not paged: it answers with every commit it pinned and sends no pagination headers, so a pagination block here could only ever be zero, and its schema would tell a model that paging applies to a write.

func Create

func Create(ctx context.Context, client *gitlabclient.Client, input CreateInput) (CreateOutput, error)

Create adds context commits to a merge request.

type DeleteInput

type DeleteInput struct {
	ProjectID    toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MergeRequest int64                `json:"merge_request_iid"     jsonschema:"Merge request IID,required"`
	Commits      []string             `json:"commits"    jsonschema:"List of commit SHAs to remove from context,required"`
}

DeleteInput is the input for deleting MR context commits.

type ListInput

type ListInput struct {
	ProjectID    toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or URL-encoded path,required"`
	MergeRequest int64                `json:"merge_request_iid"     jsonschema:"Merge request IID,required"`
	toolutil.PaginationInput
}

ListInput is the input for listing MR context commits, and the page of them to list.

GitLab pages the list: the route builds paginate(merge_request.merge_request_context_commits), which reads page and per_page from the request although the route declares neither. client-go's ListMergeRequestContextCommits takes no options struct, so the page travels as a request option.

type ListOutput

type ListOutput struct {
	toolutil.HintableOutput
	Commits    []CommitItem              `json:"commits"`
	Pagination toolutil.PaginationOutput `json:"pagination"`
}

ListOutput is the output for listing MR context commits: one page, and Pagination is where that page sits in the whole.

func List

func List(ctx context.Context, client *gitlabclient.Client, input ListInput) (ListOutput, error)

List returns one page of the context commits of a merge request.

The page is read from the captured body, since client-go's own decode fails on a commit carrying a trailer (see [capturedCommit]). The capture keeps no headers, so the pagination block comes from the response client-go returns, which it returns on that decode failure too.

Jump to

Keyboard shortcuts

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