mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-10-31 02:11:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package repo
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 
 | |
| 	"gitea.com/gitea/gitea-mcp/pkg/gitea"
 | |
| 	"gitea.com/gitea/gitea-mcp/pkg/log"
 | |
| 	"gitea.com/gitea/gitea-mcp/pkg/to"
 | |
| 
 | |
| 	gitea_sdk "code.gitea.io/sdk/gitea"
 | |
| 	"github.com/mark3labs/mcp-go/mcp"
 | |
| )
 | |
| 
 | |
| const (
 | |
| 	ListRepoCommitsToolName = "list_repo_commits"
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	ListRepoCommitsTool = mcp.NewTool(
 | |
| 		ListRepoCommitsToolName,
 | |
| 		mcp.WithDescription("List repository commits"),
 | |
| 		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
 | |
| 		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
 | |
| 		mcp.WithString("sha", mcp.Description("sha")),
 | |
| 		mcp.WithString("path", mcp.Description("path")),
 | |
| 	)
 | |
| )
 | |
| 
 | |
| func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | |
| 	log.Debugf("Called ListRepoCommitsFn")
 | |
| 	owner, ok := req.Params.Arguments["owner"].(string)
 | |
| 	if !ok {
 | |
| 		return nil, fmt.Errorf("owner is required")
 | |
| 	}
 | |
| 	repo, ok := req.Params.Arguments["repo"].(string)
 | |
| 	if !ok {
 | |
| 		return nil, fmt.Errorf("repo is required")
 | |
| 	}
 | |
| 	sha, _ := req.Params.Arguments["sha"].(string)
 | |
| 	path, _ := req.Params.Arguments["path"].(string)
 | |
| 	opt := gitea_sdk.ListCommitOptions{
 | |
| 		ListOptions: gitea_sdk.ListOptions{
 | |
| 			Page:     1,
 | |
| 			PageSize: 1000,
 | |
| 		},
 | |
| 		SHA:  sha,
 | |
| 		Path: path,
 | |
| 	}
 | |
| 	commits, _, err := gitea.Client().ListRepoCommits(owner, repo, opt)
 | |
| 	if err != nil {
 | |
| 		return nil, fmt.Errorf("list repo commits err: %v", err)
 | |
| 	}
 | |
| 	return to.TextResult(commits)
 | |
| }
 |