Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/github/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@ func listLabelsLegacy(t translations.TranslationHelperFunc) inventory.ServerTool
return utils.NewToolResultError(err.Error()), nil, nil
}

perPage, err := OptionalIntParamWithDefault(args, "perPage", listLabelsDefaultPerPage)
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
// Distinguish omitted perPage (default 100) from an explicit 0, which is out of range.
perPage := listLabelsDefaultPerPage
if _, present := args["perPage"]; present {
perPage, err = OptionalIntParam(args, "perPage")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
}
after, err := OptionalParam[string](args, "after")
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions pkg/github/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ func TestListLabels(t *testing.T) {
expectToolError: true,
expectedToolErrMsg: "perPage value 101 exceeds maximum of 100",
},
{
// Explicit 0 must not be treated as "omitted" and replaced by the default of 100.
// The mock matches first=100 so a silent default would succeed and fail this case.
name: "rejects a page size of 0",
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
"perPage": float64(0),
},
mockedClient: githubv4mock.NewMockedHTTPClient(listLabelsMatcher(100, (*githubv4.String)(nil), map[string]any{
"hasNextPage": githubv4.Boolean(false),
"hasPreviousPage": githubv4.Boolean(false),
"startCursor": githubv4.String("c1"),
"endCursor": githubv4.String("c2"),
})),
expectToolError: true,
expectedToolErrMsg: "perPage value 0 is below minimum of 1",
},
}

for _, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions pkg/github/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ func (p CursorPaginationParams) ToGraphQLParams() (*GraphQLPaginationParams, err
if p.PerPage > 100 {
return nil, fmt.Errorf("perPage value %d exceeds maximum of 100", p.PerPage)
}
if p.PerPage < 0 {
return nil, fmt.Errorf("perPage value %d cannot be negative", p.PerPage)
if p.PerPage < 1 {
return nil, fmt.Errorf("perPage value %d is below minimum of 1", p.PerPage)
}
first := int32(p.PerPage)

Expand Down