Show snapshot warnings in the summary

This commit is contained in:
Justin Holguín
2023-03-22 21:30:12 +00:00
committed by GitHub
parent f46c48ed6d
commit 419396de41
6 changed files with 83 additions and 12 deletions
Generated Vendored
+38 -6
View File
@@ -181,15 +181,28 @@ const githubUtils = __importStar(__nccwpck_require__(3030));
const retry = __importStar(__nccwpck_require__(6298)); const retry = __importStar(__nccwpck_require__(6298));
const schemas_1 = __nccwpck_require__(8774); const schemas_1 = __nccwpck_require__(8774);
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry); const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
const SnapshotWarningsHeader = 'x-github-dependency-graph-snapshot-warnings';
const octo = new retryingOctokit(githubUtils.getOctokitOptions(core.getInput('repo-token', { required: true }))); const octo = new retryingOctokit(githubUtils.getOctokitOptions(core.getInput('repo-token', { required: true })));
function compare({ owner, repo, baseRef, headRef }) { function compare({ owner, repo, baseRef, headRef }) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const changes = yield octo.paginate('GET /repos/{owner}/{repo}/dependency-graph/compare/{basehead}', { let snapshot_warnings = '';
const changes = yield octo.paginate({
method: 'GET',
url: '/repos/{owner}/{repo}/dependency-graph/compare/{basehead}',
owner, owner,
repo, repo,
basehead: `${baseRef}...${headRef}` basehead: `${baseRef}...${headRef}`
}, response => {
if (response.headers[SnapshotWarningsHeader] &&
typeof response.headers[SnapshotWarningsHeader] === 'string') {
snapshot_warnings = Buffer.from(response.headers[SnapshotWarningsHeader], 'base64').toString('utf-8');
}
return schemas_1.ChangesSchema.parse(response.data);
});
return schemas_1.ComparisonResponseSchema.parse({
changes,
snapshot_warnings
}); });
return schemas_1.ChangesSchema.parse(changes);
}); });
} }
exports.compare = compare; exports.compare = compare;
@@ -452,12 +465,14 @@ function run() {
try { try {
const config = yield (0, config_1.readConfig)(); const config = yield (0, config_1.readConfig)();
const refs = (0, git_refs_1.getRefs)(config, github.context); const refs = (0, git_refs_1.getRefs)(config, github.context);
const changes = yield dependencyGraph.compare({ const comparison = yield dependencyGraph.compare({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
baseRef: refs.base, baseRef: refs.base,
headRef: refs.head headRef: refs.head
}); });
const changes = comparison.changes;
const snapshot_warnings = comparison.snapshot_warnings;
if (!changes) { if (!changes) {
core.info('No Dependency Changes found. Skipping Dependency Review.'); core.info('No Dependency Changes found. Skipping Dependency Review.');
return; return;
@@ -473,6 +488,9 @@ function run() {
deny: config.deny_licenses deny: config.deny_licenses
}); });
summary.addSummaryToSummary(vulnerableChanges, invalidLicenseChanges, config); summary.addSummaryToSummary(vulnerableChanges, invalidLicenseChanges, config);
if (snapshot_warnings) {
summary.addSnapshotWarnings(snapshot_warnings);
}
if (config.vulnerability_check) { if (config.vulnerability_check) {
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity); summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity);
printVulnerabilitiesBlock(vulnerableChanges, minSeverity); printVulnerabilitiesBlock(vulnerableChanges, minSeverity);
@@ -630,7 +648,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ChangesSchema = exports.ConfigurationOptionsSchema = exports.PullRequestSchema = exports.ChangeSchema = exports.SeveritySchema = exports.SCOPES = exports.SEVERITIES = void 0; exports.ComparisonResponseSchema = exports.ChangesSchema = exports.ConfigurationOptionsSchema = exports.PullRequestSchema = exports.ChangeSchema = exports.SeveritySchema = exports.SCOPES = exports.SEVERITIES = void 0;
const z = __importStar(__nccwpck_require__(3301)); const z = __importStar(__nccwpck_require__(3301));
exports.SEVERITIES = ['critical', 'high', 'moderate', 'low']; exports.SEVERITIES = ['critical', 'high', 'moderate', 'low'];
exports.SCOPES = ['unknown', 'runtime', 'development']; exports.SCOPES = ['unknown', 'runtime', 'development'];
@@ -696,6 +714,10 @@ exports.ConfigurationOptionsSchema = z
} }
}); });
exports.ChangesSchema = z.array(exports.ChangeSchema); exports.ChangesSchema = z.array(exports.ChangeSchema);
exports.ComparisonResponseSchema = z.object({
changes: z.array(exports.ChangeSchema),
snapshot_warnings: z.string()
});
/***/ }), /***/ }),
@@ -729,7 +751,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addScannedDependencies = exports.addLicensesToSummary = exports.addChangeVulnerabilitiesToSummary = exports.addSummaryToSummary = void 0; exports.addSnapshotWarnings = exports.addScannedDependencies = exports.addLicensesToSummary = exports.addChangeVulnerabilitiesToSummary = exports.addSummaryToSummary = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const utils_1 = __nccwpck_require__(918); const utils_1 = __nccwpck_require__(918);
const icons = { const icons = {
@@ -887,6 +909,12 @@ function addScannedDependencies(changes) {
} }
} }
exports.addScannedDependencies = addScannedDependencies; exports.addScannedDependencies = addScannedDependencies;
function addSnapshotWarnings(warnings) {
core.summary.addHeading('Snapshot Warnings', 2);
core.summary.addQuote(`${icons.warning}: ${warnings}`);
core.summary.addRaw('See the documentation for troubleshooting help.');
}
exports.addSnapshotWarnings = addSnapshotWarnings;
function countLicenseIssues(invalidLicenseChanges) { function countLicenseIssues(invalidLicenseChanges) {
return Object.values(invalidLicenseChanges).reduce((acc, val) => acc + val.length, 0); return Object.values(invalidLicenseChanges).reduce((acc, val) => acc + val.length, 0);
} }
@@ -45083,7 +45111,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ChangesSchema = exports.ConfigurationOptionsSchema = exports.PullRequestSchema = exports.ChangeSchema = exports.SeveritySchema = exports.SCOPES = exports.SEVERITIES = void 0; exports.ComparisonResponseSchema = exports.ChangesSchema = exports.ConfigurationOptionsSchema = exports.PullRequestSchema = exports.ChangeSchema = exports.SeveritySchema = exports.SCOPES = exports.SEVERITIES = void 0;
const z = __importStar(__nccwpck_require__(3301)); const z = __importStar(__nccwpck_require__(3301));
exports.SEVERITIES = ['critical', 'high', 'moderate', 'low']; exports.SEVERITIES = ['critical', 'high', 'moderate', 'low'];
exports.SCOPES = ['unknown', 'runtime', 'development']; exports.SCOPES = ['unknown', 'runtime', 'development'];
@@ -45149,6 +45177,10 @@ exports.ConfigurationOptionsSchema = z
} }
}); });
exports.ChangesSchema = z.array(exports.ChangeSchema); exports.ChangesSchema = z.array(exports.ChangeSchema);
exports.ComparisonResponseSchema = z.object({
changes: z.array(exports.ChangeSchema),
snapshot_warnings: z.string()
});
/***/ }), /***/ }),
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+26 -4
View File
@@ -1,9 +1,14 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as githubUtils from '@actions/github/lib/utils' import * as githubUtils from '@actions/github/lib/utils'
import * as retry from '@octokit/plugin-retry' import * as retry from '@octokit/plugin-retry'
import {Changes, ChangesSchema} from './schemas' import {
ChangesSchema,
ComparisonResponse,
ComparisonResponseSchema
} from './schemas'
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry) const retryingOctokit = githubUtils.GitHub.plugin(retry.retry)
const SnapshotWarningsHeader = 'x-github-dependency-graph-snapshot-warnings'
const octo = new retryingOctokit( const octo = new retryingOctokit(
githubUtils.getOctokitOptions(core.getInput('repo-token', {required: true})) githubUtils.getOctokitOptions(core.getInput('repo-token', {required: true}))
) )
@@ -18,14 +23,31 @@ export async function compare({
repo: string repo: string
baseRef: string baseRef: string
headRef: string headRef: string
}): Promise<Changes> { }): Promise<ComparisonResponse> {
let snapshot_warnings = ''
const changes = await octo.paginate( const changes = await octo.paginate(
'GET /repos/{owner}/{repo}/dependency-graph/compare/{basehead}',
{ {
method: 'GET',
url: '/repos/{owner}/{repo}/dependency-graph/compare/{basehead}',
owner, owner,
repo, repo,
basehead: `${baseRef}...${headRef}` basehead: `${baseRef}...${headRef}`
},
response => {
if (
response.headers[SnapshotWarningsHeader] &&
typeof response.headers[SnapshotWarningsHeader] === 'string'
) {
snapshot_warnings = Buffer.from(
response.headers[SnapshotWarningsHeader],
'base64'
).toString('utf-8')
}
return ChangesSchema.parse(response.data)
} }
) )
return ChangesSchema.parse(changes) return ComparisonResponseSchema.parse({
changes,
snapshot_warnings
})
} }
+7 -1
View File
@@ -22,12 +22,14 @@ async function run(): Promise<void> {
const config = await readConfig() const config = await readConfig()
const refs = getRefs(config, github.context) const refs = getRefs(config, github.context)
const changes = await dependencyGraph.compare({ const comparison = await dependencyGraph.compare({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
baseRef: refs.base, baseRef: refs.base,
headRef: refs.head headRef: refs.head
}) })
const changes = comparison.changes
const snapshot_warnings = comparison.snapshot_warnings
if (!changes) { if (!changes) {
core.info('No Dependency Changes found. Skipping Dependency Review.') core.info('No Dependency Changes found. Skipping Dependency Review.')
@@ -65,6 +67,10 @@ async function run(): Promise<void> {
config config
) )
if (snapshot_warnings) {
summary.addSnapshotWarnings(snapshot_warnings)
}
if (config.vulnerability_check) { if (config.vulnerability_check) {
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity) summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity)
printVulnerabilitiesBlock(vulnerableChanges, minSeverity) printVulnerabilitiesBlock(vulnerableChanges, minSeverity)
+5
View File
@@ -73,9 +73,14 @@ export const ConfigurationOptionsSchema = z
}) })
export const ChangesSchema = z.array(ChangeSchema) export const ChangesSchema = z.array(ChangeSchema)
export const ComparisonResponseSchema = z.object({
changes: z.array(ChangeSchema),
snapshot_warnings: z.string()
})
export type Change = z.infer<typeof ChangeSchema> export type Change = z.infer<typeof ChangeSchema>
export type Changes = z.infer<typeof ChangesSchema> export type Changes = z.infer<typeof ChangesSchema>
export type ComparisonResponse = z.infer<typeof ComparisonResponseSchema>
export type ConfigurationOptions = z.infer<typeof ConfigurationOptionsSchema> export type ConfigurationOptions = z.infer<typeof ConfigurationOptionsSchema>
export type Severity = z.infer<typeof SeveritySchema> export type Severity = z.infer<typeof SeveritySchema>
export type Scope = (typeof SCOPES)[number] export type Scope = (typeof SCOPES)[number]
+6
View File
@@ -215,6 +215,12 @@ export function addScannedDependencies(changes: Changes): void {
} }
} }
export function addSnapshotWarnings(warnings: string): void {
core.summary.addHeading('Snapshot Warnings', 2)
core.summary.addQuote(`${icons.warning}: ${warnings}`)
core.summary.addRaw('See the documentation for troubleshooting help.')
}
function countLicenseIssues( function countLicenseIssues(
invalidLicenseChanges: InvalidLicenseChanges invalidLicenseChanges: InvalidLicenseChanges
): number { ): number {