chore(tools): centralize pagination cap helper

This commit is contained in:
Mathias Bergqvist
2026-05-04 23:06:38 +02:00
parent 4274b48ea5
commit 1f9934349b
4 changed files with 15 additions and 10 deletions

View File

@@ -76,9 +76,7 @@ func (t *CodeSearch) Call(ctx context.Context, raw json.RawMessage) (json.RawMes
if args.Page < 1 {
args.Page = 1
}
if args.Limit < 1 || args.Limit > 50 {
args.Limit = 30
}
args.Limit = capLimit(args.Limit, 30)
if args.Repo != "" {
return t.singleRepo(ctx, args)

View File

@@ -48,10 +48,8 @@ func (t *RepoList) Call(ctx context.Context, raw json.RawMessage) (json.RawMessa
if err := t.a.Check(args.Owner); err != nil {
return nil, err
}
if args.Limit == 0 || args.Limit > 50 {
args.Limit = 30
}
if args.Page == 0 {
args.Limit = capLimit(args.Limit, 30)
if args.Page < 1 {
args.Page = 1
}
repos, err := t.c.ListRepos(ctx, args.Owner, args.Page, args.Limit)

View File

@@ -60,9 +60,7 @@ func (t *RepoSearch) Call(ctx context.Context, raw json.RawMessage) (json.RawMes
if args.Page < 1 {
args.Page = 1
}
if args.Limit < 1 || args.Limit > 50 {
args.Limit = 30
}
args.Limit = capLimit(args.Limit, 30)
repos, err := t.c.SearchRepos(ctx, args.Q, args.Owner, args.Page, args.Limit)
if err != nil {

View File

@@ -22,3 +22,14 @@ func parseArgs(raw json.RawMessage, dst any) error {
}
func _ctx(ctx context.Context) context.Context { return ctx } // stub for future hooks
// capLimit returns a sane page size: 0 or negative → def, > 50 → 50.
func capLimit(in, def int) int {
if in <= 0 {
return def
}
if in > 50 {
return 50
}
return in
}