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
8 changes: 8 additions & 0 deletions pkg/github/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/github/projects/project_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 12 additions & 14 deletions pkg/github/projects/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/views/QueryEditorProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const QueryEditorProjects = (props: Props) => {
const [org, setOrg] = useState<string>(props.organization || '');
const [user, setUser] = useState<string>(props.user || '');
const [number, setNumber] = useState<number | string | undefined>(props.number);
const [maxPages, setMaxPages] = useState<number | string | undefined>(props.maxPages);
const [kind, setKind] = useState<ProjectQueryType>(props.kind || ProjectQueryType.ORG);
const [filters, setFilters] = useState<Filter[]>(props.filters || []);
const label = kind === ProjectQueryType.ORG ? 'Organization' : 'User';
Expand Down Expand Up @@ -135,6 +136,32 @@ const QueryEditorProjects = (props: Props) => {
/>
</QueryEditorRow>

<QueryEditorRow>
<InlineLabel
tooltip="The maximum number of pages to retrieve (max 30)."
width={LeftColumnWidth * 2}
>
Max. Pages
</InlineLabel>
<Input
aria-label={components.QueryEditor.Number.input}
width={RightColumnWidth}
value={maxPages}
min={1}
max={30}
type='number'
step={1}
defaultValue={2}
onChange={(el) => setMaxPages(num(el.currentTarget.value))}
onBlur={(el) =>
props.onChange({
...props,
maxPages: num(el.currentTarget.value),
})
}
/>
</QueryEditorRow>

{/* Filters currently only apply to Project Items */}
{number && (
<QueryEditorRow>
Expand Down