Unverified 提交 f90a4179 authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Handle insufficient permissions gracefully in Playwright summary (#2291)

## Summary - Fixes the merge-reports workflow failure on fork PRs (like #2276) - Wraps GitHub API calls in try-catch to handle 403 permission errors gracefully - Test results are still written to the job summary even when PR comment fails ## Test plan - [x] Verify the fix by checking the merge-reports job on this PR (should pass) #skip-bugbot 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevents merge-reports from failing on fork PRs by gracefully handling 403 permission errors when posting Playwright results. Test results still appear in the job summary even if the PR comment can’t be created or updated. - **Bug Fixes** - Wrap PR comment API calls in try/catch; on 403, log a clear message and continue without failing the workflow. - Keep update/create logic for the bot comment when permissions allow; skip safely when no PR is detected. <sup>Written for commit befdb30e68a21ddb992e0d175d91352dfe8e04e0. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
上级 dc9acbd6
...@@ -415,34 +415,46 @@ async function run({ github, context, core }) { ...@@ -415,34 +415,46 @@ async function run({ github, context, core }) {
const prNumber = determineIssueNumber({ context }); const prNumber = determineIssueNumber({ context });
if (prNumber) { if (prNumber) {
const { data: comments } = await github.rest.issues.listComments({ try {
owner: context.repo.owner, const { data: comments } = await github.rest.issues.listComments({
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(
(c) =>
c.user?.type === "Bot" &&
c.body?.includes("🎭 Playwright Test Results"),
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: prNumber, issue_number: prNumber,
body: comment,
}); });
const botComment = comments.find(
(c) =>
c.user?.type === "Bot" &&
c.body?.includes("🎭 Playwright Test Results"),
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
}
} catch (error) {
// Handle permission errors gracefully (common for fork PRs)
if (error.status === 403) {
console.log(
"Unable to post PR comment due to insufficient permissions (this is expected for fork PRs). " +
"Results are still available in the job summary.",
);
} else {
throw error;
}
} }
} else if (!prNumber) { } else {
console.log("No pull request detected; skipping PR comment"); console.log("No pull request detected; skipping PR comment");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论