Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions .github/workflows/entropy-beauty-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;

Expand All @@ -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
});
Loading