Skip to content

Commit

Permalink
Improve reporting for dependency-graph failure
Browse files Browse the repository at this point in the history
The previous message was assuming a permissions issue, and was not
including the underlying error message in the response.
  • Loading branch information
bigdaz committed Dec 19, 2023
1 parent f95e9c7 commit a198078
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,26 @@ async function submitDependencyGraphs(dependencyGraphFiles: string[]): Promise<v
await submitDependencyGraphFile(jsonFile)
} catch (error) {
if (error instanceof RequestError) {
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile)
core.warning(
`Failed to submit dependency graph ${relativeJsonFile}.\n` +
"Please ensure that the 'contents: write' permission is available for the workflow job.\n" +
"Note that this permission is never available for a 'pull_request' trigger from a repository fork."
)
core.warning(buildWarningMessage(jsonFile, error))
} else {
throw error
}
}
}
}

function buildWarningMessage(jsonFile: string, error: RequestError): string {
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile)
const mainWarning = `Failed to submit dependency graph ${relativeJsonFile}.\n${String(error)}`
if (error.message === 'Resource not accessible by integration') {
return `${mainWarning}
Please ensure that the 'contents: write' permission is available for the workflow job.
Note that this permission is never available for a 'pull_request' trigger from a repository fork.
`
}
return mainWarning
}

async function submitDependencyGraphFile(jsonFile: string): Promise<void> {
const octokit = getOctokit()
const jsonContent = fs.readFileSync(jsonFile, 'utf8')
Expand Down

0 comments on commit a198078

Please sign in to comment.