Skip to content

Commit 7d8ff3e

Browse files
committed
Pass PR number via artifact for fork PRs
For fork PRs, github.event.workflow_run.pull_requests is always empty due to GitHub security restrictions. Include PR number in the danger_report.json artifact instead.
1 parent b4d4719 commit 7d8ff3e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

.github/workflows/danger-comment.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ permissions:
1212
jobs:
1313
comment:
1414
runs-on: ubuntu-latest
15-
if: >
16-
github.event.workflow_run.event == 'pull_request' &&
17-
github.event.workflow_run.pull_requests[0]
15+
if: github.event.workflow_run.event == 'pull_request'
1816
steps:
1917
- name: Download Danger report
2018
uses: actions/download-artifact@v6
@@ -29,6 +27,11 @@ jobs:
2927
const fs = require('fs');
3028
const report = JSON.parse(fs.readFileSync('danger_report.json', 'utf8'));
3129
30+
if (!report.pr_number) {
31+
console.log('No PR number found in report, skipping comment');
32+
return;
33+
}
34+
3235
let body = '## Danger Report\n\n';
3336
3437
if (report.errors && report.errors.length > 0) {
@@ -55,11 +58,10 @@ jobs:
5558
body += ':white_check_mark: All checks passed!';
5659
}
5760
58-
const prNumber = ${{ github.event.workflow_run.pull_requests[0].number }};
5961
const { data: comments } = await github.rest.issues.listComments({
6062
owner: context.repo.owner,
6163
repo: context.repo.repo,
62-
issue_number: prNumber
64+
issue_number: report.pr_number
6365
});
6466
6567
const botComment = comments.find(c =>
@@ -78,7 +80,7 @@ jobs:
7880
await github.rest.issues.createComment({
7981
owner: context.repo.owner,
8082
repo: context.repo.repo,
81-
issue_number: prNumber,
83+
issue_number: report.pr_number,
8284
body: body
8385
});
8486
}

.github/workflows/danger.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
env:
1919
BASE_SHA: ${{ github.event.pull_request.base.sha }}
2020
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
21+
PR_NUMBER: ${{ github.event.pull_request.number }}
2122
DANGER_REPORT_PATH: danger_report.json
2223
run: bundle exec danger dry_run --base=$BASE_SHA --head=$HEAD_SHA --verbose
2324
- name: Upload Danger report

Dangerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if ENV['DANGER_REPORT_PATH']
3131
require 'json'
3232

3333
report = {
34+
pr_number: ENV['PR_NUMBER']&.to_i,
3435
errors: violation_report[:errors].map(&:message),
3536
warnings: violation_report[:warnings].map(&:message),
3637
messages: violation_report[:messages].map(&:message)

0 commit comments

Comments
 (0)