Skip to content

Commit 6f67b0a

Browse files
cmcnallyCopilot
andauthored
Don't fail the review gate when the PR comment can't be posted (#10)
Fork PRs get a read-only GITHUB_TOKEN, so posting the result comment returns 403 and kills the job even when the Official Rules document passed validation. Wrap the comment in try/catch, downgrade the failure to a warning, and always write the report to the job summary. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 468e211 commit 6f67b0a

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

‎.github/workflows/validate-official-rules.yml‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,32 @@ jobs:
9898
script: |
9999
const fs = require('fs');
100100
const marker = '<!-- official-rules-review-gate -->';
101-
const body = marker + '\n' + fs.readFileSync('report.md', 'utf8');
102-
const { owner, repo } = context.repo;
103-
const issue_number = context.payload.pull_request.number;
104-
const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number });
105-
const existing = comments.find(c => c.body && c.body.includes(marker));
106-
if (existing) {
107-
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
108-
} else {
109-
await github.rest.issues.createComment({ owner, repo, issue_number, body });
101+
const report = fs.readFileSync('report.md', 'utf8');
102+
const body = marker + '\n' + report;
103+
104+
// Always publish the report to the job summary so the result is
105+
// readable even when the token cannot write to the PR.
106+
await core.summary.addRaw(report).write();
107+
108+
try {
109+
const { owner, repo } = context.repo;
110+
const issue_number = context.payload.pull_request.number;
111+
const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number });
112+
const existing = comments.find(c => c.body && c.body.includes(marker));
113+
if (existing) {
114+
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
115+
} else {
116+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
117+
}
118+
} catch (error) {
119+
// Pull requests from forks get a read-only token, so commenting
120+
// fails with a 403. That must not fail the review gate: the gate
121+
// result comes from the validator, not from posting a comment.
122+
core.warning(
123+
'Could not post the review comment (' + error.message + '). ' +
124+
'This usually means the pull request comes from a fork, which ' +
125+
'gets a read-only token. See the job summary for the full report.'
126+
);
110127
}
111128
112129
- name: Enforce gate

0 commit comments

Comments
 (0)