-
Notifications
You must be signed in to change notification settings - Fork 54
ci: tolerate book preview comment permission errors #3635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ on: | |||||
|
|
||||||
| permissions: | ||||||
| contents: read | ||||||
| issues: write | ||||||
| pull-requests: write | ||||||
|
|
||||||
| concurrency: | ||||||
|
|
@@ -50,36 +51,44 @@ jobs: | |||||
| const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; | ||||||
| const artifactUrl = `${repoUrl}/actions/runs/${runId}`; | ||||||
|
|
||||||
| const { data: comments } = await github.rest.issues.listComments({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| issue_number: prNumber, | ||||||
| }); | ||||||
|
|
||||||
| const marker = '<!-- book-preview -->'; | ||||||
| const existing = comments.find(c => c.body.includes(marker)); | ||||||
| const body = [ | ||||||
| marker, | ||||||
| `📖 **Book Preview** built successfully.`, | ||||||
| ``, | ||||||
| `Download the preview from the [workflow artifacts](${artifactUrl}).`, | ||||||
| `To view locally: download the artifact, unzip, and open \`index.html\`.`, | ||||||
| ``, | ||||||
| `_Updated at ${new Date().toISOString()}_`, | ||||||
| ].join('\n'); | ||||||
|
|
||||||
| if (existing) { | ||||||
| await github.rest.issues.updateComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| comment_id: existing.id, | ||||||
| body, | ||||||
| }); | ||||||
| } else { | ||||||
| await github.rest.issues.createComment({ | ||||||
| try { | ||||||
| const { data: comments } = await github.rest.issues.listComments({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| issue_number: prNumber, | ||||||
| body, | ||||||
| }); | ||||||
|
Comment on lines
+55
to
59
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick:
source: ['claude'] |
||||||
|
|
||||||
| const marker = '<!-- book-preview -->'; | ||||||
| const existing = comments.find(c => c.body.includes(marker)); | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick:
💡 Suggested change
Suggested change
source: ['claude'] |
||||||
| const body = [ | ||||||
| marker, | ||||||
| `📖 **Book Preview** built successfully.`, | ||||||
| ``, | ||||||
| `Download the preview from the [workflow artifacts](${artifactUrl}).`, | ||||||
| `To view locally: download the artifact, unzip, and open \`index.html\`.`, | ||||||
| ``, | ||||||
| `_Updated at ${new Date().toISOString()}_`, | ||||||
| ].join('\n'); | ||||||
|
|
||||||
| if (existing) { | ||||||
| await github.rest.issues.updateComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| comment_id: existing.id, | ||||||
| body, | ||||||
| }); | ||||||
| } else { | ||||||
| await github.rest.issues.createComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| issue_number: prNumber, | ||||||
| body, | ||||||
| }); | ||||||
| } | ||||||
| } catch (error) { | ||||||
| if (error?.status === 403 && String(error?.message ?? '').includes('Resource not accessible by integration')) { | ||||||
| core.warning('Skipping book preview PR comment because this workflow token cannot write comments for the event.'); | ||||||
| } else { | ||||||
| throw error; | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Nitpick:
issues: writehas no effect for fork PRs under thepull_requesttriggerWith the
pull_requesttrigger (line 4, notpull_request_target), GITHUB_TOKEN is forced read-only for PRs from forks regardless of declaredpermissions. Soissues: writeandpull-requests: writeonly 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']