From 1c691affb58d0c6e8048eb5fd84e681e9da4bb22 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:01:15 -0800 Subject: [PATCH 1/2] warn on perm issues instead of failure --- dist/index.js | 142 +++++++++++++++++++++-------------- src/github/github_comment.ts | 141 +++++++++++++++++++++------------- 2 files changed, 173 insertions(+), 110 deletions(-) diff --git a/dist/index.js b/dist/index.js index c834d5b..2d1bbf1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35827,8 +35827,28 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.upsertGitHubComment = upsertGitHubComment; exports.upsertGitHubCommentV2 = upsertGitHubCommentV2; const github_1 = __nccwpck_require__(5438); +const core_1 = __nccwpck_require__(2186); const ts_dedent_1 = __importDefault(__nccwpck_require__(3604)); const url_1 = __nccwpck_require__(1650); +const isPermissionError = (error) => { + if (error instanceof Error) { + const message = error.message.toLowerCase(); + return (message.includes('resource not accessible by integration') || + message.includes('permission') || + message.includes('403')); + } + return false; +}; +const handleCommentError = (error, action) => { + if (isPermissionError(error)) { + (0, core_1.warning)(`Skipping GitHub comment (${action}): insufficient permissions. ` + + `To enable comments, add 'contents: write' and 'pull-requests: write' to your workflow permissions. ` + + `See: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs`); + } + else { + throw error; + } +}; async function upsertGitHubComment(testSuiteId, githubToken, resp) { const octokit = (0, github_1.getOctokit)(githubToken); const projectId = resp.result?.projectId || ''; @@ -35891,37 +35911,42 @@ async function upsertGitHubComment(testSuiteId, githubToken, resp) { : { data: [] }; const existingCommentId = comments.find(comment => comment?.body?.startsWith(commentIdentiifer))?.id; // Create or update commit/PR comment - if (github_1.context.payload.pull_request) { - if (existingCommentId) { - await octokit.rest.issues.updateComment({ - ...github_1.context.repo, - comment_id: existingCommentId, - body - }); + try { + if (github_1.context.payload.pull_request) { + if (existingCommentId) { + await octokit.rest.issues.updateComment({ + ...github_1.context.repo, + comment_id: existingCommentId, + body + }); + } + else { + await octokit.rest.issues.createComment({ + ...github_1.context.repo, + body, + issue_number: github_1.context.payload.pull_request.number + }); + } } - else { - await octokit.rest.issues.createComment({ - ...github_1.context.repo, - body, - issue_number: github_1.context.payload.pull_request.number - }); + else if (commitSha) { + if (existingCommentId) { + await octokit.rest.repos.updateCommitComment({ + ...github_1.context.repo, + comment_id: existingCommentId, + body + }); + } + else { + await octokit.rest.repos.createCommitComment({ + ...github_1.context.repo, + body, + commit_sha: commitSha + }); + } } } - else if (commitSha) { - if (existingCommentId) { - await octokit.rest.repos.updateCommitComment({ - ...github_1.context.repo, - comment_id: existingCommentId, - body - }); - } - else { - await octokit.rest.repos.createCommitComment({ - ...github_1.context.repo, - body, - commit_sha: commitSha - }); - } + catch (error) { + handleCommentError(error, 'upsertGitHubComment'); } } function listTestMarkDown({ testSuiteRunId, tests, projectId }) { @@ -35986,37 +36011,42 @@ async function upsertGitHubCommentV2(projectId, runId, githubToken, resp, runGro : { data: [] }; const existingCommentId = comments.find(comment => comment?.body?.startsWith(commentIdentiifer))?.id; // Create or update commit/PR comment - if (github_1.context.payload.pull_request) { - if (existingCommentId) { - await octokit.rest.issues.updateComment({ - ...github_1.context.repo, - comment_id: existingCommentId, - body - }); + try { + if (github_1.context.payload.pull_request) { + if (existingCommentId) { + await octokit.rest.issues.updateComment({ + ...github_1.context.repo, + comment_id: existingCommentId, + body + }); + } + else { + await octokit.rest.issues.createComment({ + ...github_1.context.repo, + body, + issue_number: github_1.context.payload.pull_request.number + }); + } } - else { - await octokit.rest.issues.createComment({ - ...github_1.context.repo, - body, - issue_number: github_1.context.payload.pull_request.number - }); + else if (commitSha) { + if (existingCommentId) { + await octokit.rest.repos.updateCommitComment({ + ...github_1.context.repo, + comment_id: existingCommentId, + body + }); + } + else { + await octokit.rest.repos.createCommitComment({ + ...github_1.context.repo, + body, + commit_sha: commitSha + }); + } } } - else if (commitSha) { - if (existingCommentId) { - await octokit.rest.repos.updateCommitComment({ - ...github_1.context.repo, - comment_id: existingCommentId, - body - }); - } - else { - await octokit.rest.repos.createCommitComment({ - ...github_1.context.repo, - body, - commit_sha: commitSha - }); - } + catch (error) { + handleCommentError(error, 'upsertGitHubCommentV2'); } } diff --git a/src/github/github_comment.ts b/src/github/github_comment.ts index 2fd9335..507b83b 100644 --- a/src/github/github_comment.ts +++ b/src/github/github_comment.ts @@ -1,9 +1,34 @@ +import { warning } from '@actions/core'; import { context, getOctokit } from '@actions/github'; import dedent from 'ts-dedent'; import type { ResultResponse } from '../stably/api/agent-api'; import type { PlaywrightResultResponse } from '../stably/api/playwright-api'; import { getSuiteRunDashboardUrl } from '../stably/url'; +const isPermissionError = (error: unknown): boolean => { + if (error instanceof Error) { + const message = error.message.toLowerCase(); + return ( + message.includes('resource not accessible by integration') || + message.includes('permission') || + message.includes('403') + ); + } + return false; +}; + +const handleCommentError = (error: unknown, action: string): void => { + if (isPermissionError(error)) { + warning( + `Skipping GitHub comment (${action}): insufficient permissions. ` + + `To enable comments, add 'contents: write' and 'pull-requests: write' to your workflow permissions. ` + + `See: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs` + ); + } else { + throw error; + } +}; + export async function upsertGitHubComment( testSuiteId: string, githubToken: string, @@ -85,34 +110,38 @@ export async function upsertGitHubComment( )?.id; // Create or update commit/PR comment - if (context.payload.pull_request) { - if (existingCommentId) { - await octokit.rest.issues.updateComment({ - ...context.repo, - comment_id: existingCommentId, - body - }); - } else { - await octokit.rest.issues.createComment({ - ...context.repo, - body, - issue_number: context.payload.pull_request.number - }); - } - } else if (commitSha) { - if (existingCommentId) { - await octokit.rest.repos.updateCommitComment({ - ...context.repo, - comment_id: existingCommentId, - body - }); - } else { - await octokit.rest.repos.createCommitComment({ - ...context.repo, - body, - commit_sha: commitSha - }); + try { + if (context.payload.pull_request) { + if (existingCommentId) { + await octokit.rest.issues.updateComment({ + ...context.repo, + comment_id: existingCommentId, + body + }); + } else { + await octokit.rest.issues.createComment({ + ...context.repo, + body, + issue_number: context.payload.pull_request.number + }); + } + } else if (commitSha) { + if (existingCommentId) { + await octokit.rest.repos.updateCommitComment({ + ...context.repo, + comment_id: existingCommentId, + body + }); + } else { + await octokit.rest.repos.createCommitComment({ + ...context.repo, + body, + commit_sha: commitSha + }); + } } + } catch (error) { + handleCommentError(error, 'upsertGitHubComment'); } } @@ -214,33 +243,37 @@ export async function upsertGitHubCommentV2( )?.id; // Create or update commit/PR comment - if (context.payload.pull_request) { - if (existingCommentId) { - await octokit.rest.issues.updateComment({ - ...context.repo, - comment_id: existingCommentId, - body - }); - } else { - await octokit.rest.issues.createComment({ - ...context.repo, - body, - issue_number: context.payload.pull_request.number - }); - } - } else if (commitSha) { - if (existingCommentId) { - await octokit.rest.repos.updateCommitComment({ - ...context.repo, - comment_id: existingCommentId, - body - }); - } else { - await octokit.rest.repos.createCommitComment({ - ...context.repo, - body, - commit_sha: commitSha - }); + try { + if (context.payload.pull_request) { + if (existingCommentId) { + await octokit.rest.issues.updateComment({ + ...context.repo, + comment_id: existingCommentId, + body + }); + } else { + await octokit.rest.issues.createComment({ + ...context.repo, + body, + issue_number: context.payload.pull_request.number + }); + } + } else if (commitSha) { + if (existingCommentId) { + await octokit.rest.repos.updateCommitComment({ + ...context.repo, + comment_id: existingCommentId, + body + }); + } else { + await octokit.rest.repos.createCommitComment({ + ...context.repo, + body, + commit_sha: commitSha + }); + } } + } catch (error) { + handleCommentError(error, 'upsertGitHubCommentV2'); } } From 1d8c9ddbae09769ed6728ea7300bc84595482ff8 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:39:22 -0800 Subject: [PATCH 2/2] add file --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 2d1bbf1..079f270 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35826,8 +35826,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.upsertGitHubComment = upsertGitHubComment; exports.upsertGitHubCommentV2 = upsertGitHubCommentV2; -const github_1 = __nccwpck_require__(5438); const core_1 = __nccwpck_require__(2186); +const github_1 = __nccwpck_require__(5438); const ts_dedent_1 = __importDefault(__nccwpck_require__(3604)); const url_1 = __nccwpck_require__(1650); const isPermissionError = (error) => {