mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 09:02:50 +00:00
Warn when permissions not set for PR comment
This commit is contained in:
parent
d16a3f4093
commit
a4107da76d
1 changed files with 28 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary'
|
||||
import {RequestError} from '@octokit/request-error'
|
||||
|
||||
import * as params from './input-params'
|
||||
import {BuildResult} from './build-results'
|
||||
|
@ -30,9 +31,6 @@ export async function generateJobSummary(buildResults: BuildResult[], cacheListe
|
|||
}
|
||||
|
||||
async function addPRComment(jobSummary: string): Promise<void> {
|
||||
try {
|
||||
const github_token = params.getGithubToken()
|
||||
|
||||
const context = github.context
|
||||
if (context.payload.pull_request == null) {
|
||||
core.info('No pull_request trigger: not adding PR comment')
|
||||
|
@ -47,16 +45,33 @@ async function addPRComment(jobSummary: string): Promise<void> {
|
|||
|
||||
${jobSummary}`
|
||||
|
||||
const github_token = params.getGithubToken()
|
||||
const octokit = github.getOctokit(github_token)
|
||||
try {
|
||||
await octokit.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: pull_request_number,
|
||||
body: prComment
|
||||
})
|
||||
} catch (error) {
|
||||
core.warning(`Failed to generate PR comment: ${String(error)}`)
|
||||
if (error instanceof RequestError) {
|
||||
core.warning(buildWarningMessage(error))
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildWarningMessage(error: RequestError): string {
|
||||
const mainWarning = `Failed to generate PR comment.\n${String(error)}`
|
||||
if (error.message === 'Resource not accessible by integration') {
|
||||
return `${mainWarning}
|
||||
Please ensure that the 'pull-requests: write' permission is available for the workflow job.
|
||||
Note that this permission is never available for a workflow triggered from a repository fork.
|
||||
`
|
||||
}
|
||||
return mainWarning
|
||||
}
|
||||
|
||||
function renderSummaryTable(results: BuildResult[]): string {
|
||||
if (results.length === 0) {
|
||||
|
|
Loading…
Reference in a new issue