From 00bc738696d33f316f0c2475ac33f88581b6e91f Mon Sep 17 00:00:00 2001 From: Markus Hoeckner Date: Tue, 30 Sep 2025 07:30:15 +0200 Subject: [PATCH] feat: add MaxPages option to project queries and update related logic --- pkg/github/datasource.go | 8 ++++++++ pkg/github/projects/project_items.go | 4 ++-- pkg/github/projects/projects.go | 26 ++++++++++++-------------- pkg/models/projects.go | 2 ++ src/views/QueryEditorProjects.tsx | 27 +++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/pkg/github/datasource.go b/pkg/github/datasource.go index bd8a4196..2cb3abde 100644 --- a/pkg/github/datasource.go +++ b/pkg/github/datasource.go @@ -157,11 +157,19 @@ func (d *Datasource) HandleProjectsQuery(ctx context.Context, query *models.Proj opt := models.ProjectOptions{ Organization: query.Options.Organization, Number: query.Options.Number, + MaxPages: query.Options.MaxPages, User: query.Options.User, Kind: query.Options.Kind, Filters: query.Options.Filters, } + // Validate and set defaults for MaxPages - ensure between 1 and 30 + if opt.MaxPages <= 0 { + opt.MaxPages = 1 + } else if opt.MaxPages > 30 { + opt.MaxPages = 30 + } + if projects.ProjectNumber(query.Options.Number) > 0 { return projects.GetAllProjectItems(ctx, d.client, opt) } diff --git a/pkg/github/projects/project_items.go b/pkg/github/projects/project_items.go index 895a052b..9ec4048e 100644 --- a/pkg/github/projects/project_items.go +++ b/pkg/github/projects/project_items.go @@ -147,7 +147,7 @@ func getAllProjectItemsByOrg(ctx context.Context, client models.Client, opts mod ) var fields []Field - for i := 0; i < PageNumberLimit; i++ { + for i := 0; i < opts.MaxPages; i++ { q := &QueryProject{} if err := client.Query(ctx, q, variables); err != nil { return nil, errors.WithStack(err) @@ -181,7 +181,7 @@ func getAllProjectItemsByUser(ctx context.Context, client models.Client, opts mo ) var fields []Field - for i := 0; i < PageNumberLimit; i++ { + for i := 0; i < opts.MaxPages; i++ { q := &QueryProjectByUser{} if err := client.Query(ctx, q, variables); err != nil { return nil, errors.WithStack(err) diff --git a/pkg/github/projects/projects.go b/pkg/github/projects/projects.go index 5c5fb5be..c7f1296f 100644 --- a/pkg/github/projects/projects.go +++ b/pkg/github/projects/projects.go @@ -11,19 +11,17 @@ import ( "github.com/shurcooL/githubv4" ) -// PageNumberLimit is the limit on the number of pages that will be traversed -const PageNumberLimit = 2 - // QueryListProjects lists all projects in a repository -// organization(login: "grafana") { -// projectsV2(first: 100) { -// nodes { -// id -// title -// ... -// } -// } -// } +// +// organization(login: "grafana") { +// projectsV2(first: 100) { +// nodes { +// id +// title +// ... +// } +// } +// } type QueryListProjects struct { Organization struct { ProjectsV2 struct { @@ -122,7 +120,7 @@ func getAllProjectsByOrg(ctx context.Context, client models.Client, opts models. projects = Projects{} ) - for i := 0; i < PageNumberLimit; i++ { + for i := 0; i < opts.MaxPages; i++ { q := &QueryListProjects{} if err := client.Query(ctx, q, variables); err != nil { return nil, errors.WithStack(err) @@ -151,7 +149,7 @@ func getAllProjectsByUser(ctx context.Context, client models.Client, opts models projects = Projects{} ) - for i := 0; i < PageNumberLimit; i++ { + for i := 0; i < opts.MaxPages; i++ { q := &QueryListProjectsByUser{} if err := client.Query(ctx, q, variables); err != nil { return nil, errors.WithStack(err) diff --git a/pkg/models/projects.go b/pkg/models/projects.go index 897f5269..9e6f2621 100644 --- a/pkg/models/projects.go +++ b/pkg/models/projects.go @@ -18,6 +18,8 @@ type ProjectOptions struct { Organization string `json:"organization"` // Number is the project number Number any `json:"number"` + // Pages is the maximum number of pages to retrieve (max 30) + MaxPages int `json:"maxPages"` // User is the name of the user who owns the project being queried User string `json:"user"` // Kind is the kind of query - Org vs User diff --git a/src/views/QueryEditorProjects.tsx b/src/views/QueryEditorProjects.tsx index 9265b451..3dcec893 100644 --- a/src/views/QueryEditorProjects.tsx +++ b/src/views/QueryEditorProjects.tsx @@ -45,6 +45,7 @@ const QueryEditorProjects = (props: Props) => { const [org, setOrg] = useState(props.organization || ''); const [user, setUser] = useState(props.user || ''); const [number, setNumber] = useState(props.number); + const [maxPages, setMaxPages] = useState(props.maxPages); const [kind, setKind] = useState(props.kind || ProjectQueryType.ORG); const [filters, setFilters] = useState(props.filters || []); const label = kind === ProjectQueryType.ORG ? 'Organization' : 'User'; @@ -135,6 +136,32 @@ const QueryEditorProjects = (props: Props) => { /> + + + Max. Pages + + setMaxPages(num(el.currentTarget.value))} + onBlur={(el) => + props.onChange({ + ...props, + maxPages: num(el.currentTarget.value), + }) + } + /> + + {/* Filters currently only apply to Project Items */} {number && (