Skip to content

Bug: Code Scanning alerts query only returns 30 results (no pagination) #773

Description

@amitdisha

Summary

The Code Scanning query type only returns the first 30 alerts regardless of how many exist in the repository or
organization. This is because the GetCodeScanningAlerts function makes a single API call with no pagination loop and no
PerPage override (so GitHub's default of 30 applies).

Steps to Reproduce

  1. Configure a GitHub datasource panel with Query Type = Code Scanning
  2. Set State = open on a repository with more than 30 alerts
  3. Observe that exactly 30 results are returned regardless of the true count

Expected Behavior

All matching alerts are returned, consistent with how other query types (e.g. Dependabot vulnerabilities) paginate through
results.

Actual Behavior

Root Cause

In pkg/github/codescanning.go, GetCodeScanningAlerts calls ListAlertsForRepo / ListAlertsForOrg once with no
ListOptions.PerPage set and no loop to fetch subsequent pages:

alerts, _, err = c.ListAlertsForRepo(
    context,
    opt.Owner,
    opt.Repository,
    &googlegithub.AlertListOptions{
        State: opt.State,
        Ref:   opt.Ref,
    },
)

By contrast, the Dependabot vulnerabilities implementation correctly uses a for loop with PageInfo.HasNextPage to paginate
all results.

This was noted as a known gap in the original draft PR #377 ("fetch more than just the first 100") but was not addressed
before the feature shipped in #462.

Environment

- Plugin version: v2.1.6 through v2.8.0 (latest) — all affected
- Grafana version: tested on 11.4.0
- Affects both repo-level and org-level Code Scanning queries

Suggested Fix

Add a pagination loop to GetCodeScanningAlerts using ListOptions.Page / Response.NextPage, following the same pattern used
in the Dependabot vulnerabilities implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions