Skip to content

Commit

Permalink
Better warning
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Dec 19, 2023
1 parent 58d37ce commit c9bc776
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
17 changes: 12 additions & 5 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93696,11 +93696,10 @@ function submitDependencyGraphs(dependencyGraphFiles) {
}
catch (error) {
if (error instanceof request_error_1.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.info(JSON.stringify(error));
core.info(`error.name = ${error.name}`);
core.info(`error.message = ${error.message}`);
core.info(`error.response = ${error.response}`);
core.warning(buildWarningMessage(jsonFile, error));
}
else {
throw error;
Expand All @@ -93709,6 +93708,14 @@ function submitDependencyGraphs(dependencyGraphFiles) {
}
});
}
function buildWarningMessage(jsonFile, error) {
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
const mainWarning = `Failed to submit dependency graph ${relativeJsonFile}.\n${error.message}`;
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.
`;
}
function submitDependencyGraphFile(jsonFile) {
return __awaiter(this, void 0, void 0, function* () {
const octokit = getOctokit();
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93696,11 +93696,10 @@ function submitDependencyGraphs(dependencyGraphFiles) {
}
catch (error) {
if (error instanceof request_error_1.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.info(JSON.stringify(error));
core.info(`error.name = ${error.name}`);
core.info(`error.message = ${error.message}`);
core.info(`error.response = ${error.response}`);
core.warning(buildWarningMessage(jsonFile, error));
}
else {
throw error;
Expand All @@ -93709,6 +93708,14 @@ function submitDependencyGraphs(dependencyGraphFiles) {
}
});
}
function buildWarningMessage(jsonFile, error) {
const relativeJsonFile = getRelativePathFromWorkspace(jsonFile);
const mainWarning = `Failed to submit dependency graph ${relativeJsonFile}.\n${error.message}`;
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.
`;
}
function submitDependencyGraphFile(jsonFile) {
return __awaiter(this, void 0, void 0, function* () {
const octokit = getOctokit();
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions src/dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,27 @@ 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.info(JSON.stringify(error))
core.info(`error.name = ${error.name}`)
core.info(`error.message = ${error.message}`)
core.info(`error.response = ${error.response}`)

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${error.message}`
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.
`
}

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

0 comments on commit c9bc776

Please sign in to comment.