From 71711aff9af2542ee65e0e8c594d15d78a8bd52d Mon Sep 17 00:00:00 2001 From: David Karnok Date: Wed, 5 Aug 2026 10:40:10 +0200 Subject: [PATCH] Update GitHub Actions workflow for comment posting --- .github/workflows/entropy-beauty-comment.yml | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/entropy-beauty-comment.yml b/.github/workflows/entropy-beauty-comment.yml index 834463027d..82ef3cec23 100644 --- a/.github/workflows/entropy-beauty-comment.yml +++ b/.github/workflows/entropy-beauty-comment.yml @@ -8,11 +8,12 @@ on: permissions: contents: read pull-requests: write + actions: read # needed to download artifacts from other runs jobs: comment: if: > - github.event.workflow_run.event == 'pull_request_target' && + github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: @@ -22,19 +23,22 @@ jobs: name: scan-results run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} + path: results - name: Post summary comment uses: actions/github-script@v7 with: script: | const fs = require('fs'); + const path = require('path'); - if (!fs.existsSync('scan-summary.json')) { + const summaryPath = path.join('results', 'scan-summary.json'); + if (!fs.existsSync(summaryPath)) { core.setFailed('scan-summary.json missing — analysis did not produce results'); return; } - const summary = JSON.parse(fs.readFileSync('scan-summary.json', 'utf8')); + const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8')); const beauty = summary.beauty || {}; const findingsCount = summary.findings_count || 0; @@ -54,15 +58,34 @@ jobs: body += `\n*Mid-4 beauty heuristic in action — powered by our entropy chats! 😊*`; + // Robust PR number lookup + let prNumber = null; const prs = github.event.workflow_run.pull_requests || []; - if (prs.length === 0) { - console.log('No associated PR found'); + if (prs.length > 0) { + prNumber = prs[0].number; + } else { + // Fallback: look up open PRs by head SHA + const headSha = github.event.workflow_run.head_sha; + const { data: found } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${github.event.workflow_run.head_repository.owner.login}:${github.event.workflow_run.head_branch}` + }); + if (found.length > 0) { + prNumber = found[0].number; + } + } + + if (!prNumber) { + console.log('No associated PR found (even after fallback lookup)'); + console.log(JSON.stringify(github.event.workflow_run, null, 2)); return; } await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: prs[0].number, + issue_number: prNumber, body: body });