Skip to content

Paginate Code Scanning alerts instead of returning only the first page#777

Merged
mattvella07 merged 1 commit into
grafana:mainfrom
Tarasusrus:fix/codescanning-pagination
Jul 16, 2026
Merged

Paginate Code Scanning alerts instead of returning only the first page#777
mattvella07 merged 1 commit into
grafana:mainfrom
Tarasusrus:fix/codescanning-pagination

Conversation

@Tarasusrus

Copy link
Copy Markdown
Contributor

What this PR does

Fixes #773.

GetCodeScanningAlerts made a single ListAlertsForRepo / ListAlertsForOrg call with no pagination loop and no PerPage override, so GitHub's default page size of 30 applied. Any repository or organization with more than 30 code scanning alerts silently returned only the first 30, regardless of the true count.

Fix

Loop over pages using resp.NextPage with PerPage: 100, the same idiom already used by the other paginated queries (e.g. GetAllDeployments in deployments.go). ListOptions is referenced explicitly because AlertListOptions also embeds ListCursorOptions, which would make a bare Page/PerPage ambiguous.

Tests

Extended the code scanning mock client to serve successive pages and added TestGetCodeScanningAlertsPagination:

  • repository query walks 3 pages (3 + 3 + 2 alerts) and returns all 8, requesting pages 1, 2, 3 in order.
  • organization query walks 2 pages and returns all 4.

Existing single-page tests continue to pass. go test ./pkg/... is green.

GetCodeScanningAlerts made a single ListAlertsForRepo/ListAlertsForOrg call
with no pagination and no PerPage override, so GitHub's default page size of
30 applied and any repository/org with more than 30 alerts silently returned
only the first 30.

Loop over pages using resp.NextPage (PerPage 100), matching how the other
paginated queries (e.g. deployments) already work.

Fixes grafana#773

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Tarasusrus Tarasusrus requested a review from a team as a code owner July 4, 2026 06:53
@cla-assistant

cla-assistant Bot commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant

cla-assistant Bot commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mattvella07 mattvella07 self-assigned this Jul 10, 2026

@mattvella07 mattvella07 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattvella07

mattvella07 commented Jul 13, 2026

Copy link
Copy Markdown

@Tarasusrus Please sign the CLA

@mattvella07

Copy link
Copy Markdown

@Tarasusrus Let me know once you sign the CLA so I can make sure that the license/cla check is working

@Tarasusrus

Tarasusrus commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@mattvella07 Signed — license/cla is now green here and on #778.

The only remaining red check is Add issue to project, which fails only on fork PRs: #777 and #778 fail, while #776, #779, #780 and #782 — all branches in this repo — pass. It dies in create-github-app-token with Unable to get ACTIONS_ID_TOKEN_REQUEST_URL, i.e. the OIDC token isn't exposed to workflows triggered from a fork, so it can't mint the app token. Unrelated to this change, but it does mean the job can never go green on an outside contribution.

Everything else — build, docs, and the full Playwright E2E matrix — is green. Ready to merge from my side. Thanks for the review!

@mattvella07

Copy link
Copy Markdown

@Tarasusrus Thanks! That check is to help us keep track of PRs, so its not required to pass. I'll go head and merge. Thanks for the contribution!

@mattvella07 mattvella07 merged commit cd18886 into grafana:main Jul 16, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants