-
Notifications
You must be signed in to change notification settings - Fork 14
Fix CodeQL workflow: correct alert collection bug and improve fork PR handling #249
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
Merged
knoepfel
merged 9 commits into
Framework-R-D:main
from
greenc-FNAL:bugfix/codeql-pr-comments
Jan 13, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fd6e64a
Fix CodeQL workflow: correct alert collection bug and improve fork PR…
Copilot d9e5be0
Improve error message clarity for missing comment file
Copilot 5bbc5fe
Add blank line after headling
greenc-FNAL a363ed0
Improve API handling for alerts
greenc-FNAL 57a528d
Really enable PR comments this time
greenc-FNAL 5b543e8
Apply Python linting fixes
github-actions[bot] 3a61e10
Update `CodeQL-README.md` per copilot code review.
greenc-FNAL 32b5793
Address `mypy` complaint
greenc-FNAL 66d86ea
Remove unnecessary comments
greenc-FNAL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: "CodeQL - Post Comment" | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["CodeQL - Analyze (C++, Python, Actions)"] | ||
| types: | ||
| - completed | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| jobs: | ||
| post-comment: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'cancelled' | ||
| steps: | ||
| - name: Download PR comment data | ||
| uses: actions/download-artifact@fa0a91b85d4f404e8442c7c958156baef1102941 # v4.1.8 | ||
| with: | ||
| name: codeql-pr-data | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.WORKFLOW_PAT }} # Needed to download artifacts from other runs if private/internal | ||
| path: pr_comment_data | ||
| continue-on-error: true | ||
|
|
||
| - name: Post Comment | ||
| # Only run if the artifact was found (meaning alerts exist) | ||
| if: success() && hashFiles('pr_comment_data/pr_number.txt') != '' | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| github-token: ${{ secrets.WORKFLOW_PAT }} | ||
| script: | | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const prNumberPath = path.join('pr_comment_data', 'pr_number.txt'); | ||
| const commentBodyPath = path.join('pr_comment_data', 'comment_body.md'); | ||
|
|
||
| if (!fs.existsSync(prNumberPath) || !fs.existsSync(commentBodyPath)) { | ||
| console.log('Artifact data missing, skipping comment.'); | ||
| return; | ||
| } | ||
|
|
||
| const prNumber = Number(fs.readFileSync(prNumberPath, 'utf8').trim()); | ||
| const body = fs.readFileSync(commentBodyPath, 'utf8'); | ||
| const marker = '<!-- codeql-alerts -->'; | ||
| const legacyMarker = '<!-- codeql-new-alerts -->'; | ||
|
|
||
| // Append marker if missing | ||
| const finalBody = body.includes(marker) ? body : `${body}\n${marker}`; | ||
|
|
||
| console.log(`Processing PR #${prNumber}`); | ||
|
|
||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
|
|
||
| const existing = comments.find(c => c.body.includes(marker) || c.body.includes(legacyMarker)); | ||
|
|
||
| if (existing) { | ||
| console.log(`Updating existing comment ${existing.id}`); | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body: finalBody | ||
| }); | ||
| } else { | ||
| console.log(`Creating new comment`); | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: finalBody | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.