Add min-comment to fix max-comment length issue

This commit is contained in:
Justin Hutchings
2024-05-06 00:26:50 +00:00
committed by Eli Reisman
parent 8d625cd32e
commit 48fae2e703
5 changed files with 138 additions and 8 deletions

View File

@@ -12,14 +12,20 @@ const octo = new retryingOctokit(
// Comment Marker to identify an existing comment to update, so we don't spam the PR with comments
const COMMENT_MARKER = '<!-- dependency-review-pr-comment-marker -->'
const MAX_COMMENT_LENGTH = 65536
export async function commentPr(
summary: typeof core.summary,
config: ConfigurationOptions
config: ConfigurationOptions,
minComment: string
): Promise<void> {
const commentContent = summary.stringify()
core.setOutput('comment-content', commentContent)
if (commentContent.length >= MAX_COMMENT_LENGTH) {
core.setOutput('comment-content', minComment)
} else {
core.setOutput('comment-content', commentContent)
}
if (
!(

View File

@@ -134,6 +134,13 @@ async function run(): Promise<void> {
scorecard,
config
)
const minSummary = summary.getMinSummaryForComment(
vulnerableChanges,
invalidLicenseChanges,
deniedChanges,
scorecard,
config
)
if (snapshot_warnings) {
summary.addSnapshotWarnings(config, snapshot_warnings)
@@ -166,7 +173,7 @@ async function run(): Promise<void> {
core.setOutput('dependency-changes', JSON.stringify(changes))
summary.addScannedDependencies(changes)
printScannedDependencies(changes)
await commentPr(core.summary, config)
await commentPr(core.summary, config, minSummary)
} catch (error) {
if (error instanceof RequestError && error.status === 404) {
core.setFailed(

View File

@@ -10,6 +10,70 @@ const icons = {
warning: '⚠️'
}
export function getMinSummaryForComment(
vulnerableChanges: Changes,
invalidLicenseChanges: InvalidLicenseChanges,
deniedChanges: Changes,
scorecard: Scorecard,
config: ConfigurationOptions
): string {
const scorecardWarnings = countScorecardWarnings(scorecard, config)
const licenseIssues = countLicenseIssues(invalidLicenseChanges)
let minSummary = '# Dependency Review\n'
if (
vulnerableChanges.length === 0 &&
licenseIssues === 0 &&
deniedChanges.length === 0 &&
scorecardWarnings === 0
) {
const issueTypes = [
config.vulnerability_check ? 'vulnerabilities' : '',
config.license_check ? 'license issues' : '',
config.show_openssf_scorecard ? 'OpenSSF Scorecard issues' : ''
]
if (issueTypes.filter(Boolean).length === 0) {
minSummary += `${icons.check} No issues found.`
} else {
minSummary += `${icons.check} No ${issueTypes.filter(Boolean).join(' or ')} found.`
}
}
minSummary += 'The following issues were found:\n'
minSummary += config.vulnerability_check
? `* ${checkOrFailIcon(vulnerableChanges.length)} ${
vulnerableChanges.length
} vulnerable package(s)\n`
: ''
minSummary += config.license_check
? `* ${checkOrFailIcon(invalidLicenseChanges.forbidden.length)} ${
invalidLicenseChanges.forbidden.length
} package(s) with incompatible licenses\n
* ${checkOrFailIcon(invalidLicenseChanges.unresolved.length)} ${
invalidLicenseChanges.unresolved.length
} package(s) with invalid SPDX license definitions\n
* ${checkOrWarnIcon(invalidLicenseChanges.unlicensed.length)} ${
invalidLicenseChanges.unlicensed.length
} package(s) with unknown licenses.\n`
: ''
minSummary +=
deniedChanges.length > 0
? `* ${checkOrWarnIcon(deniedChanges.length)} ${
deniedChanges.length
} package(s) denied.\n`
: ''
minSummary +=
config.show_openssf_scorecard && scorecardWarnings > 0
? `* ${checkOrWarnIcon(scorecardWarnings)} ${scorecardWarnings ? scorecardWarnings : 'No'} packages with OpenSSF Scorecard issues.\n`
: ''
// Add the link to the job summary provided by GitHub Actions for this workflow run
minSummary += `\n[View full job summary](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})`
return minSummary
}
export function addSummaryToSummary(
vulnerableChanges: Changes,
invalidLicenseChanges: InvalidLicenseChanges,