mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-10-30 01:41:50 +00:00 
			
		
		
		
	Add EditIssue (#30)
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/30 Reviewed-by: hiifong <i@hiif.ong> Co-authored-by: yp05327 <576951401@qq.com> Co-committed-by: yp05327 <576951401@qq.com>
This commit is contained in:
		| @@ -172,6 +172,7 @@ The Gitea MCP Server supports the following tools: | ||||
| |       list_repo_issues       |    Issue     |            List all issues in a repository            | | ||||
| |         create_issue         |    Issue     |                  Create a new issue                   | | ||||
| |     create_issue_comment     |    Issue     |             Create a comment on an issue              | | ||||
| |          edit_issue          |    Issue     |                      Edit a issue                     | | ||||
| |  get_pull_request_by_index   | Pull Request |            Get a pull request by its index            | | ||||
| |   list_repo_pull_requests    | Pull Request |        List all pull requests in a repository         | | ||||
| |     create_pull_request      | Pull Request |               Create a new pull request               | | ||||
|   | ||||
| @@ -172,6 +172,7 @@ Gitea MCP 服务器支持以下工具: | ||||
| |       list_repo_issues       |   问题   |     列出仓库中的所有问题     | | ||||
| |         create_issue         |   问题   |        创建一个新问题        | | ||||
| |     create_issue_comment     |   问题   |       在问题上创建评论       | | ||||
| |          edit_issue          |   问题   |         编辑一个问题        | | ||||
| |  get_pull_request_by_index   | 拉取请求 |     根据索引获取拉取请求     | | ||||
| |   list_repo_pull_requests    | 拉取请求 |   列出仓库中的所有拉取请求   | | ||||
| |     create_pull_request      | 拉取请求 |      创建一个新拉取请求      | | ||||
|   | ||||
| @@ -171,6 +171,7 @@ Gitea MCP 伺服器支持以下工具: | ||||
| |       list_repo_issues       |   問題   |     列出倉庫中的所有問題     | | ||||
| |         create_issue         |   問題   |        創建一個新問題        | | ||||
| |     create_issue_comment     |   問題   |       在問題上創建評論       | | ||||
| |          edit_issue          |   問題   |         編輯一個問題        | | ||||
| |  get_pull_request_by_index   | 拉取請求 |     根據索引獲取拉取請求     | | ||||
| |   list_repo_pull_requests    | 拉取請求 |   列出倉庫中的所有拉取請求   | | ||||
| |     create_pull_request      | 拉取請求 |      創建一個新拉取請求      | | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import ( | ||||
|  | ||||
| 	"gitea.com/gitea/gitea-mcp/pkg/gitea" | ||||
| 	"gitea.com/gitea/gitea-mcp/pkg/log" | ||||
| 	"gitea.com/gitea/gitea-mcp/pkg/ptr" | ||||
| 	"gitea.com/gitea/gitea-mcp/pkg/to" | ||||
|  | ||||
| 	gitea_sdk "code.gitea.io/sdk/gitea" | ||||
| @@ -18,6 +19,7 @@ const ( | ||||
| 	ListRepoIssuesToolName     = "list_repo_issues" | ||||
| 	CreateIssueToolName        = "create_issue" | ||||
| 	CreateIssueCommentToolName = "create_issue_comment" | ||||
| 	EditIssueToolName          = "edit_issue" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -55,6 +57,18 @@ var ( | ||||
| 		mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")), | ||||
| 		mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")), | ||||
| 	) | ||||
| 	EditIssueTool = mcp.NewTool( | ||||
| 		EditIssueToolName, | ||||
| 		mcp.WithDescription("edit issue"), | ||||
| 		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")), | ||||
| 		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")), | ||||
| 		mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")), | ||||
| 		mcp.WithString("title", mcp.Description("issue title"), mcp.DefaultString("")), | ||||
| 		mcp.WithString("body", mcp.Description("issue body content")), | ||||
| 		mcp.WithArray("assignees", mcp.Description("usernames to assign to this issue"), mcp.Items(map[string]interface{}{"type": "string"})), | ||||
| 		mcp.WithNumber("milestone", mcp.Description("milestone number")), | ||||
| 		mcp.WithString("state", mcp.Description("issue state, one of open, closed, all")), | ||||
| 	) | ||||
| ) | ||||
|  | ||||
| func RegisterTool(s *server.MCPServer) { | ||||
| @@ -62,6 +76,7 @@ func RegisterTool(s *server.MCPServer) { | ||||
| 	s.AddTool(ListRepoIssuesTool, ListRepoIssuesFn) | ||||
| 	s.AddTool(CreateIssueTool, CreateIssueFn) | ||||
| 	s.AddTool(CreateIssueCommentTool, CreateIssueCommentFn) | ||||
| 	s.AddTool(EditIssueTool, EditIssueFn) | ||||
| } | ||||
|  | ||||
| func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||||
| @@ -179,3 +194,49 @@ func CreateIssueCommentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.Ca | ||||
|  | ||||
| 	return to.TextResult(issueComment) | ||||
| } | ||||
|  | ||||
| func EditIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||||
| 	log.Debugf("Called EditIssueFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	index, ok := req.Params.Arguments["index"].(float64) | ||||
| 	if !ok { | ||||
| 		return to.ErrorResult(fmt.Errorf("index is required")) | ||||
| 	} | ||||
|  | ||||
| 	opt := gitea_sdk.EditIssueOption{} | ||||
|  | ||||
| 	title, ok := req.Params.Arguments["title"].(string) | ||||
| 	if ok { | ||||
| 		opt.Title = title | ||||
| 	} | ||||
| 	body, ok := req.Params.Arguments["body"].(string) | ||||
| 	if ok { | ||||
| 		opt.Body = ptr.To(body) | ||||
| 	} | ||||
| 	assignees, ok := req.Params.Arguments["assignees"].([]string) | ||||
| 	if ok { | ||||
| 		opt.Assignees = assignees | ||||
| 	} | ||||
| 	milestone, ok := req.Params.Arguments["milestone"].(float64) | ||||
| 	if ok { | ||||
| 		opt.Milestone = ptr.To(int64(milestone)) | ||||
| 	} | ||||
| 	state, ok := req.Params.Arguments["state"].(string) | ||||
| 	if ok { | ||||
| 		opt.State = ptr.To(gitea_sdk.StateType(state)) | ||||
| 	} | ||||
|  | ||||
| 	issue, _, err := gitea.Client().EditIssue(owner, repo, int64(index), opt) | ||||
| 	if err != nil { | ||||
| 		return to.ErrorResult(fmt.Errorf("edit %v/%v/issue/%v err: %v", owner, repo, int64(index), err)) | ||||
| 	} | ||||
|  | ||||
| 	return to.TextResult(issue) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user