Skip to content

Commit fe1ae47

Browse files
akurtakovCopilot
andcommitted
Make license review PR comment best-effort
Pull requests opened from forks run with a read-only GITHUB_TOKEN, so creating a comment fails with 'Resource not accessible by integration'. Wrap the comment creation in a try/catch so this no longer raises an unhandled error: the dependency list is still written to the job summary and the run is still marked as failed. Same-repo PRs and the /request-license-review issue_comment flow can still post the comment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 796dd8e commit fe1ae47

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

.github/workflows/licensecheck.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,20 @@ jobs:
192192
core.summary.addRaw(body).write();
193193
const prNumber = context.issue && context.issue.number;
194194
if (prNumber) {
195-
await github.rest.issues.createComment({
196-
owner: context.repo.owner,
197-
repo: context.repo.repo,
198-
issue_number: prNumber,
199-
body,
200-
});
195+
// Posting a comment requires a token with write access. For pull
196+
// requests opened from forks the GITHUB_TOKEN is read-only, so the
197+
// comment can't be posted there; the '/request-license-review'
198+
// issue_comment flow runs in the base repo and can comment instead.
199+
try {
200+
await github.rest.issues.createComment({
201+
owner: context.repo.owner,
202+
repo: context.repo.repo,
203+
issue_number: prNumber,
204+
body,
205+
});
206+
} catch (err) {
207+
core.warning(`Could not post review comment (likely a fork pull request with a read-only token): ${err}`);
208+
}
201209
} else {
202210
core.info('No pull request context available; skipping PR comment.');
203211
}

0 commit comments

Comments
 (0)