Skip to content

Commit 62bcbfc

Browse files
authored
Minor tweaks
1 parent 2b36a5a commit 62bcbfc

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

pkg/github/__toolsnaps__/get_project.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Get project",
44
"readOnlyHint": true
55
},
6-
"description": "Get Project for a user or organization",
6+
"description": "Get Project for an user or organization",
77
"inputSchema": {
88
"properties": {
99
"owner": {

pkg/github/projects.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) (
4242
if err != nil {
4343
return mcp.NewToolResultError(err.Error()), nil
4444
}
45-
4645
client, err := getClient(ctx)
4746
if err != nil {
4847
return mcp.NewToolResultError(err.Error()), nil
@@ -56,11 +55,14 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) (
5655
}
5756
projects := []github.ProjectV2{}
5857

59-
opts := ListProjectsOptions{PerPage: perPage}
58+
opts := listProjectsOptions{PerPage: perPage}
6059

6160
if queryStr != "" {
6261
opts.Query = queryStr
6362
}
63+
if perPage > 0 {
64+
opts.PerPage = perPage
65+
}
6466
url, err = addOptions(url, opts)
6567
if err != nil {
6668
return nil, fmt.Errorf("failed to add options to request: %w", err)
@@ -99,7 +101,7 @@ func ListProjects(getClient GetClientFn, t translations.TranslationHelperFunc) (
99101

100102
func GetProject(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
101103
return mcp.NewTool("get_project",
102-
mcp.WithDescription(t("TOOL_GET_PROJECT_DESCRIPTION", "Get Project for a user or organization")),
104+
mcp.WithDescription(t("TOOL_GET_PROJECT_DESCRIPTION", "Get Project for an user or organization")),
103105
mcp.WithToolAnnotation(mcp.ToolAnnotation{Title: t("TOOL_GET_PROJECT_USER_TITLE", "Get project"), ReadOnlyHint: ToBoolPtr(true)}),
104106
mcp.WithNumber("project_number", mcp.Required(), mcp.Description("The project's number")),
105107
mcp.WithString("owner_type", mcp.Required(), mcp.Description("Owner type"), mcp.Enum("user", "organization")),
@@ -133,14 +135,14 @@ func GetProject(getClient GetClientFn, t translations.TranslationHelperFunc) (to
133135
url = fmt.Sprintf("users/%s/projectsV2/%d", owner, projectNumber)
134136
}
135137

136-
projects := []github.ProjectV2{}
138+
project := github.ProjectV2{}
137139

138140
httpRequest, err := client.NewRequest("GET", url, nil)
139141
if err != nil {
140142
return nil, fmt.Errorf("failed to create request: %w", err)
141143
}
142144

143-
resp, err := client.Do(ctx, httpRequest, &projects)
145+
resp, err := client.Do(ctx, httpRequest, &project)
144146
if err != nil {
145147
return ghErrors.NewGitHubAPIErrorResponse(ctx,
146148
"failed to get project",
@@ -157,7 +159,7 @@ func GetProject(getClient GetClientFn, t translations.TranslationHelperFunc) (to
157159
}
158160
return mcp.NewToolResultError(fmt.Sprintf("failed to get project: %s", string(body))), nil
159161
}
160-
r, err := json.Marshal(projects)
162+
r, err := json.Marshal(project)
161163
if err != nil {
162164
return nil, fmt.Errorf("failed to marshal response: %w", err)
163165
}
@@ -166,7 +168,7 @@ func GetProject(getClient GetClientFn, t translations.TranslationHelperFunc) (to
166168
}
167169
}
168170

169-
type ListProjectsOptions struct {
171+
type listProjectsOptions struct {
170172
// For paginated result sets, the number of results to include per page.
171173
PerPage int `url:"per_page,omitempty"`
172174

pkg/github/projects_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
)
1616

1717
func Test_ListProjects(t *testing.T) {
18-
// Verify tool definition and schema once
1918
mockClient := gh.NewClient(nil)
2019
tool, _ := ListProjects(stubGetClientFn(mockClient), translations.NullTranslationHelper)
2120
require.NoError(t, toolsnaps.Test(tool.Name, tool))
@@ -28,7 +27,6 @@ func Test_ListProjects(t *testing.T) {
2827
assert.Contains(t, tool.InputSchema.Properties, "per_page")
2928
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "owner_type"})
3029

31-
// Minimal project objects (fields chosen to likely exist on ProjectV2; test only asserts round-trip JSON array length)
3230
orgProjects := []map[string]any{{"id": 1, "title": "Org Project"}}
3331
userProjects := []map[string]any{{"id": 2, "title": "User Project"}}
3432

@@ -176,15 +174,13 @@ func Test_GetProject(t *testing.T) {
176174
assert.Contains(t, tool.InputSchema.Properties, "owner_type")
177175
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"project_number", "owner", "owner_type"})
178176

179-
// Minimal project object for response array
180-
project := []map[string]any{{"id": 123, "title": "Project Title"}}
177+
project := map[string]any{"id": 123, "title": "Project Title"}
181178

182179
tests := []struct {
183180
name string
184181
mockedClient *http.Client
185182
requestArgs map[string]interface{}
186183
expectError bool
187-
expectedLength int
188184
expectedErrMsg string
189185
}{
190186
{
@@ -200,8 +196,7 @@ func Test_GetProject(t *testing.T) {
200196
"owner": "octo-org",
201197
"owner_type": "organization",
202198
},
203-
expectError: false,
204-
expectedLength: 1,
199+
expectError: false,
205200
},
206201
{
207202
name: "success user project fetch",
@@ -216,8 +211,7 @@ func Test_GetProject(t *testing.T) {
216211
"owner": "octocat",
217212
"owner_type": "user",
218213
},
219-
expectError: false,
220-
expectedLength: 1,
214+
expectError: false,
221215
},
222216
{
223217
name: "api error",
@@ -292,10 +286,9 @@ func Test_GetProject(t *testing.T) {
292286

293287
require.False(t, result.IsError)
294288
textContent := getTextResult(t, result)
295-
var arr []map[string]any
289+
var arr map[string]any
296290
err = json.Unmarshal([]byte(textContent.Text), &arr)
297291
require.NoError(t, err)
298-
assert.Equal(t, tc.expectedLength, len(arr))
299292
})
300293
}
301294
}

0 commit comments

Comments
 (0)