Skip to content

Commit 71711af

Browse files
authored
Update GitHub Actions workflow for comment posting
1 parent 5dcdacb commit 71711af

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

.github/workflows/entropy-beauty-comment.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ on:
88
permissions:
99
contents: read
1010
pull-requests: write
11+
actions: read # needed to download artifacts from other runs
1112

1213
jobs:
1314
comment:
1415
if: >
15-
github.event.workflow_run.event == 'pull_request_target' &&
16+
github.event.workflow_run.event == 'pull_request' &&
1617
github.event.workflow_run.conclusion == 'success'
1718
runs-on: ubuntu-latest
1819
steps:
@@ -22,19 +23,22 @@ jobs:
2223
name: scan-results
2324
run-id: ${{ github.event.workflow_run.id }}
2425
github-token: ${{ secrets.GITHUB_TOKEN }}
26+
path: results
2527

2628
- name: Post summary comment
2729
uses: actions/github-script@v7
2830
with:
2931
script: |
3032
const fs = require('fs');
33+
const path = require('path');
3134
32-
if (!fs.existsSync('scan-summary.json')) {
35+
const summaryPath = path.join('results', 'scan-summary.json');
36+
if (!fs.existsSync(summaryPath)) {
3337
core.setFailed('scan-summary.json missing — analysis did not produce results');
3438
return;
3539
}
3640
37-
const summary = JSON.parse(fs.readFileSync('scan-summary.json', 'utf8'));
41+
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
3842
const beauty = summary.beauty || {};
3943
const findingsCount = summary.findings_count || 0;
4044
@@ -54,15 +58,34 @@ jobs:
5458
5559
body += `\n*Mid-4 beauty heuristic in action — powered by our entropy chats! 😊*`;
5660
61+
// Robust PR number lookup
62+
let prNumber = null;
5763
const prs = github.event.workflow_run.pull_requests || [];
58-
if (prs.length === 0) {
59-
console.log('No associated PR found');
64+
if (prs.length > 0) {
65+
prNumber = prs[0].number;
66+
} else {
67+
// Fallback: look up open PRs by head SHA
68+
const headSha = github.event.workflow_run.head_sha;
69+
const { data: found } = await github.rest.pulls.list({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
state: 'open',
73+
head: `${github.event.workflow_run.head_repository.owner.login}:${github.event.workflow_run.head_branch}`
74+
});
75+
if (found.length > 0) {
76+
prNumber = found[0].number;
77+
}
78+
}
79+
80+
if (!prNumber) {
81+
console.log('No associated PR found (even after fallback lookup)');
82+
console.log(JSON.stringify(github.event.workflow_run, null, 2));
6083
return;
6184
}
6285
6386
await github.rest.issues.createComment({
6487
owner: context.repo.owner,
6588
repo: context.repo.repo,
66-
issue_number: prs[0].number,
89+
issue_number: prNumber,
6790
body: body
6891
});

0 commit comments

Comments
 (0)