mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-25 17:47:44 +00:00
e2052d903f
This PR contains the following updates: | Package | Type | Update | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---|---|---| | [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) ([changelog](https://github.com/docker/setup-buildx-action/compare/bb05f3f5519dd87d3ba754cc423b652a5edd6d2c..37fe631027851001ddb9b187196cc803df7f5f0e)) | action | digest | `bb05f3f` → `37fe631` | | | | [go](https://go.dev/) ([source](https://github.com/golang/go)) | toolchain | minor | `1.26.6` → `1.27.0` |  |  | | golang.org/x/vuln | | minor | `v1.6.0` → `v1.7.0` |  |  | --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - Between 12:00 AM and 03:59 AM, only on Monday (`* 0-3 * * 1`) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTEuMiIsInVwZGF0ZWRJblZlciI6IjQzLjE5MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> --------- Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/243 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Renovate Bot <renovate-bot@gitea.com>
111 lines
3.4 KiB
Go
111 lines
3.4 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.com/gitea/gitea-mcp/pkg/annotation"
|
|
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
|
"gitea.com/gitea/gitea-mcp/pkg/params"
|
|
"gitea.com/gitea/gitea-mcp/pkg/to"
|
|
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
|
|
|
gitea_sdk "gitea.dev/sdk"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// CommitTool holds the commit-related tools (scope "commit").
|
|
var CommitTool = tool.New("commit")
|
|
|
|
const (
|
|
ListRepoCommitsToolName = "list_commits"
|
|
GetCommitToolName = "get_commit"
|
|
)
|
|
|
|
var (
|
|
ListRepoCommitsTool = tool.NewDefinition(
|
|
ListRepoCommitsToolName,
|
|
"List commits in a repository, optionally starting from a specific branch or SHA and filtered to commits touching a given file path.",
|
|
annotation.ReadOnly("List repository commits"),
|
|
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
|
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
|
tool.String("sha", tool.Description("starting SHA or branch")),
|
|
tool.String("path", tool.Description("only commits touching this path")),
|
|
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1), tool.Minimum(1)),
|
|
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30), tool.Minimum(1)),
|
|
)
|
|
|
|
GetCommitTool = tool.NewDefinition(
|
|
GetCommitToolName,
|
|
"Get details for a single commit in a repository by its SHA.",
|
|
annotation.ReadOnly("Get commit details"),
|
|
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
|
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
|
tool.String("sha", tool.Required()),
|
|
)
|
|
)
|
|
|
|
func init() {
|
|
CommitTool.RegisterRead(tool.ServerTool{
|
|
Tool: ListRepoCommitsTool,
|
|
Handler: ListRepoCommitsFn,
|
|
})
|
|
CommitTool.RegisterRead(tool.ServerTool{
|
|
Tool: GetCommitTool,
|
|
Handler: GetCommitFn,
|
|
})
|
|
}
|
|
|
|
func ListRepoCommitsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
owner, err := params.GetString(args, "owner")
|
|
if err != nil {
|
|
return to.ErrorResult(err)
|
|
}
|
|
repo, err := params.GetString(args, "repo")
|
|
if err != nil {
|
|
return to.ErrorResult(err)
|
|
}
|
|
page, pageSize := params.GetPagination(args, 30)
|
|
sha, _ := args["sha"].(string)
|
|
path, _ := args["path"].(string)
|
|
opt := gitea_sdk.ListCommitOptions{
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
SHA: sha,
|
|
Path: path,
|
|
}
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
commits, _, err := client.Repositories.ListRepoCommits(ctx, owner, repo, opt)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("list repo commits err: %v", err))
|
|
}
|
|
return to.TextResult(slimCommits(commits))
|
|
}
|
|
|
|
func GetCommitFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
owner, err := params.GetString(args, "owner")
|
|
if err != nil {
|
|
return to.ErrorResult(err)
|
|
}
|
|
repo, err := params.GetString(args, "repo")
|
|
if err != nil {
|
|
return to.ErrorResult(err)
|
|
}
|
|
sha, err := params.GetString(args, "sha")
|
|
if err != nil {
|
|
return to.ErrorResult(err)
|
|
}
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
commit, _, err := client.Repositories.GetSingleCommit(ctx, owner, repo, sha)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get commit %v err: %v", sha, err))
|
|
}
|
|
return to.TextResult(slimCommit(commit))
|
|
}
|