ci: tolerate book preview comment permission errors#3635
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe book preview workflow is updated to grant ChangesBook Preview PR Comment Posting
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
✅ Review complete (commit 181f512) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Small CI fix that wraps the book-preview comment logic in try/catch swallowing 403 'Resource not accessible by integration' and grants issues: write/pull-requests: write. The change is correct and well-scoped. Three nitpicks flagged by Claude are all verified against the file; Codex had no findings.
Reviewed commit: 181f512
💬 3 nitpick(s)
| }); | ||
|
|
||
| const marker = '<!-- book-preview -->'; | ||
| const existing = comments.find(c => c.body.includes(marker)); |
There was a problem hiding this comment.
💬 Nitpick: c.body.includes(marker) will throw if a comment body is null
listComments can return entries whose body is null (e.g., deleted/redacted comments). comments.find(c => c.body.includes(marker)) would then throw a TypeError. The new catch block only swallows 403s with the specific 'Resource not accessible by integration' message — a TypeError would be rethrown and fail the workflow with a confusing error. Defensive null-coalescing avoids it.
💡 Suggested change
| const existing = comments.find(c => c.body.includes(marker)); | |
| const existing = comments.find(c => (c.body ?? '').includes(marker)); |
source: ['claude']
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body, | ||
| }); |
There was a problem hiding this comment.
💬 Nitpick: listComments is not paginated; long-lived PRs can produce duplicate preview comments
github.rest.issues.listComments returns a single page (default 30, max 100). On a PR with many comments, the existing <!-- book-preview --> marker may live on a later page, so the workflow creates a new comment on each push instead of updating in place. Use github.paginate(github.rest.issues.listComments, {...}) to scan all comments. Not a functional bug — just a UX paper-cut.
source: ['claude']
| permissions: | ||
| contents: read | ||
| issues: write | ||
| pull-requests: write |
There was a problem hiding this comment.
💬 Nitpick: issues: write has no effect for fork PRs under the pull_request trigger
With the pull_request trigger (line 4, not pull_request_target), GITHUB_TOKEN is forced read-only for PRs from forks regardless of declared permissions. So issues: write and pull-requests: write only take effect for branch PRs in the same repository — the new try/catch is what actually keeps fork-PR runs green. A short inline comment noting that fork PRs intentionally skip commenting would help the next maintainer reading this workflow.
source: ['claude']
Book preview comment permission handling
Issue being fixed or feature implemented
The Book Preview workflow can build mdBook successfully and still fail on
fork-style PR runs when the final
actions/github-scriptstep cannot create orupdate a PR comment with the preview artifact link.
This is currently surfacing as red CI on #3092 even though the
preview build and artifact upload completed.
What was done?
issues: writeto the workflow permissions because PR comments use theIssues comments API.
403 Resource not accessible by integrationhandler.still visible.
How Has This Been Tested?
python3YAML parse of.github/workflows/book-preview.ymlpassed.git diff --checkpassed.shipforupstream/v3.1-dev..fix-book-preview-comment-permission.Breaking Changes
None.
Checklist
corresponding section if my code contains any
For repository code-owners and collaborators only
Summary by CodeRabbit