-
Notifications
You must be signed in to change notification settings - Fork 10
Make CodeQL PR comments actually useful #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
greenc-FNAL
commented
Nov 14, 2025
- Useful utility scripts for dealing with CodeQL alerts and report files
- PR comments now actually report something useful
|
Review the full CodeQL report for details. |
knoepfel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greenc-FNAL, thanks for the PR. I have several questions/comments. I'm not sure that the resolution of any of them should hold up this PR.
It's unclear to me what level of rigor we should apply to code that has been generated by AI. I think we should at least be able to vet what the code is doing, but that can be difficult, and this PR is not an exception to that.
|
@jules please resolve the following error with the CodeQL CI check: The relevant agent task is https://jules.google.com/session/2491371005401655318/code/scripts/check_codeql_alerts.py |
- Provide token where needed
- Fix CI workflow errors
- Fix AI thinko
- Work around comment permissions issue
- Getting into the weeds
- Refactor CodeQL workflow to fix PR commenting
This change addresses the failure of the CodeQL workflow to comment on pull requests. The previous implementation was overly complex, with two separate workflows attempting to handle analysis and commenting, leading to permission errors.
- Deleted `.github/workflows/codeql-comment.yml`, a redundant workflow that was created as a workaround.
- Updated `.github/workflows/codeql-analysis.yaml` to grant it `pull-requests: write` permissions, allowing it to post comments directly on PRs.
- Removed the unnecessary artifact upload steps from the main workflow, as the comment is now posted directly.
This consolidates all CodeQL logic into a single, streamlined workflow that now has the correct permissions to function as intended.
- Refactor CodeQL debug log handling for clarity and reliability
This change streamlines the handling of the debug log in the CodeQL workflow.
- The `check_codeql_alerts.py` script now accepts a `--log-path` argument, removing the hardcoded log file path.
- The `codeql-analysis.yaml` workflow now defines the log path in a single environment variable and passes it to the script.
- The redundant "fallback" log upload step has been removed, and the primary upload step has been renamed for clarity.
This makes the debug log handling more robust, maintainable, and easier to understand.
- Refine CodeQL script logic and PR comment content
- Refactor CodeQL script for clarity and maintainability:
- Consolidated duplicated summary-printing logic into a single `_print_summary` function.
- This improves maintainability and ensures consistent output.
- Refine PR comment to focus on PR-specific changes:
- Removed the comparison against the repository's 'main' branch from the PR comment.
- The comment now only shows alerts that are new or fixed relative to the PR's branch point and its previous commit.
- This makes the comment more concise and directly relevant to the changes in the pull request.
- Fix CodeQL workflow validation error
This change corrects a workflow syntax error caused by referencing the `runner` context in a job-level `env` block.
- The invalid `CODEQL_ALERTS_LOG_PATH` environment variable has been removed from the `codeql-report` job.
- A new initial step, "Set log file path," has been added to the `codeql-report` job. This step correctly defines the log file path using `$RUNNER_TEMP` and makes it available to subsequent steps via a step output.
- The script invocation and artifact upload steps have been updated to reference this new step output.
This resolves the "Unrecognized named-value: 'runner'" error and ensures the workflow is valid.
This change adjusts the format of the CodeQL PR comment to be more concise and directly relevant to the pull request's lifecycle. - The "Alert Matching Summary," which compared the PR to the `main` branch, has been replaced with a more focused summary. - The new summary highlights the number of new and fixed alerts relative to the PR's **branch point** and its **previous commit**. - This provides developers with a clearer, more actionable summary of how the PR has impacted the CodeQL alerts within its own context. - The detailed lists of new and fixed alerts for these comparisons are preserved.
Co-authored-by: Kyle Knoepfel <knoepfel@fnal.gov>
- Replace the `in locals()` check for variable existence with a more explicit pattern of initializing variables to `None` and then checking `is not None`.
Refactor the `check_codeql_alerts.py` script to improve its structure and remove all uses of `locals()`. - The large `main()` function has been broken down into smaller, more focused helper functions (`_compare_alerts_via_api` and `_build_multi_section_comment`). - A new `APIAlertComparison` dataclass is used to provide a clear data structure for API comparison results. - This refactoring eliminates the need for `locals()` by ensuring variables are properly initialized and passed between functions.
Refactor the `check_codeql_alerts.py` script to improve its structure and remove all uses of `locals()`. - The large `main()` function has been broken down into smaller, more focused helper functions (`_compare_alerts_via_api` and `_build_multi_section_comment`). - A new `APIAlertComparison` dataclass is used to provide a clear data structure for API comparison results. - This refactoring eliminates the need for `locals()` by ensuring variables are properly initialized and passed between functions. Fixes the following bugs introduced during the refactoring: - A `NameError` caused by incorrect class definition order. - A regression where matched alerts were no longer reported in the summary output. - A regression in the logic for when to post a PR comment.
e46e6ca to
0bc5cad
Compare