Ensure creating comments cannot fail job.

This commit is contained in:
Fabio Niephaus
2022-11-08 18:15:51 +01:00
parent d53592711c
commit 79e8ca0cfa
3 changed files with 23 additions and 7 deletions

View File

@@ -127,9 +127,15 @@ export async function createPRComment(content: string): Promise<void> {
throw new Error('Not a PR event.')
}
const context = github.context
await github.getOctokit(getGitHubToken()).rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request?.number as number,
body: content
})
try {
await github.getOctokit(getGitHubToken()).rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request?.number as number,
body: content
})
} catch (err) {
core.error(
`Failed to create pull request comment. Please make sure this job has 'write' permissions for the 'pull-requests' scope (see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions)? Internal error: ${err}`
)
}
}