mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-27 18:47:44 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bfc1ff17da |
@@ -49,6 +49,7 @@ var (
|
||||
tool.Array("milestones", tool.Description("milestone name or ID filter"), tool.Items(map[string]any{"type": "string"})),
|
||||
tool.String("since", tool.Description("updated after ISO 8601")),
|
||||
tool.String("before", tool.Description("updated before ISO 8601")),
|
||||
tool.String("assigned_by", tool.Description("filter by the user who assigned the issue")),
|
||||
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
||||
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
||||
)
|
||||
@@ -204,6 +205,9 @@ func listRepoIssuesFn(ctx context.Context, args map[string]any) (*mcp.CallToolRe
|
||||
if t := params.GetOptionalTime(args, "before"); t != nil {
|
||||
opt.Before = *t
|
||||
}
|
||||
if assignedBy, ok := args["assigned_by"].(string); ok {
|
||||
opt.AssignedBy = assignedBy
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
|
||||
@@ -61,12 +61,13 @@ func Test_listRepoIssuesFn_filters(t *testing.T) {
|
||||
}()
|
||||
|
||||
args := map[string]any{
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"type": "issues",
|
||||
"labels": []any{"bug", "enhancement"},
|
||||
"milestones": []any{"v1.0", "2"},
|
||||
"since": "2026-01-01T00:00:00Z",
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"type": "issues",
|
||||
"labels": []any{"bug", "enhancement"},
|
||||
"milestones": []any{"v1.0", "2"},
|
||||
"since": "2026-01-01T00:00:00Z",
|
||||
"assigned_by": "octocat",
|
||||
}
|
||||
|
||||
_, err := listRepoIssuesFn(context.Background(), args)
|
||||
@@ -89,6 +90,9 @@ func Test_listRepoIssuesFn_filters(t *testing.T) {
|
||||
if !strings.Contains(gotQuery, "type=issues") {
|
||||
t.Fatalf("expected type query param, got %s", gotQuery)
|
||||
}
|
||||
if !strings.Contains(gotQuery, "assigned_by=octocat") {
|
||||
t.Fatalf("expected assigned_by query param, got %s", gotQuery)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_listRepoIssuesFn_includesMilestone(t *testing.T) {
|
||||
@@ -138,6 +142,52 @@ func Test_listRepoIssuesFn_includesMilestone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_listRepoIssuesFn_includesAssignees(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
repo = "demo"
|
||||
)
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/version":
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"version":"1.12.0"}`))
|
||||
case fmt.Sprintf("/api/v1/repos/%s/%s", owner, repo):
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"private":false}`))
|
||||
case fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner, repo):
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`[
|
||||
{"number": 1, "title": "with assignees", "state": "open", "assignees": [{"login": "octocat"}]}
|
||||
]`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
})
|
||||
server := httptest.NewServer(handler)
|
||||
defer server.Close()
|
||||
|
||||
origHost, origToken, origVersion := flag.Host, flag.Token, flag.Version
|
||||
flag.Host, flag.Token, flag.Version = server.URL, "", "test"
|
||||
defer func() { flag.Host, flag.Token, flag.Version = origHost, origToken, origVersion }()
|
||||
|
||||
args := map[string]any{
|
||||
"owner": owner, "repo": repo,
|
||||
}
|
||||
res, err := listRepoIssuesFn(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatalf("listRepoIssuesFn() error = %v", err)
|
||||
}
|
||||
if res.IsError {
|
||||
t.Fatalf("unexpected error result: %v", res.Content)
|
||||
}
|
||||
body := res.Content[0].(*mcp.TextContent).Text
|
||||
if !strings.Contains(body, `"assignees"`) || !strings.Contains(body, `"octocat"`) {
|
||||
t.Fatalf("expected assignees in list output, got: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_createIssueFn_labels(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
|
||||
@@ -63,6 +63,9 @@ func slimIssues(issues []*gitea_sdk.Issue) []map[string]any {
|
||||
if len(i.Labels) > 0 {
|
||||
m["labels"] = slim.LabelNames(i.Labels)
|
||||
}
|
||||
if len(i.Assignees) > 0 {
|
||||
m["assignees"] = slim.UserLogins(i.Assignees)
|
||||
}
|
||||
if i.Milestone != nil {
|
||||
m["milestone"] = map[string]any{
|
||||
"id": i.Milestone.ID,
|
||||
|
||||
Reference in New Issue
Block a user