diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 2dac6716d2c1afa05e26de6cd2bc0eec3dfcd1ee..865d7a63b289e7dd41c069d2ea43b7af45dfbbaf 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -1692,7 +1692,7 @@ const options: RenovateOptions[] = [ 'Pull Request body template. Controls which sections are rendered in the body.', type: 'string', default: - '{{{header}}}{{{table}}}{{{notes}}}{{{changelogs}}}{{{configDescription}}}{{{controls}}}{{{footer}}}', + '{{{header}}}{{{table}}}{{{warnings}}}{{{notes}}}{{{changelogs}}}{{{configDescription}}}{{{controls}}}{{{footer}}}', cli: false, }, { diff --git a/lib/workers/repository/errors-warnings.spec.ts b/lib/workers/repository/errors-warnings.spec.ts index 80f40e19626656170c72d9ad35a2cedea0bdae0a..8fbb5ba7843f9eb2c4cab35899d74d329eee0437 100644 --- a/lib/workers/repository/errors-warnings.spec.ts +++ b/lib/workers/repository/errors-warnings.spec.ts @@ -2,6 +2,7 @@ import { RenovateConfig, getConfig } from '../../../test/util'; import type { PackageFile } from '../../modules/manager/types'; import { getDepWarningsDashboard, + getDepWarningsOnboardingPR, getDepWarningsPR, getErrors, getWarnings, @@ -49,7 +50,8 @@ describe('workers/repository/errors-warnings', () => { jest.resetAllMocks(); }); - it('returns pr warning text', () => { + it('returns 2 pr warnings text dependencyDashboard true', () => { + const dependencyDashboard = true; const packageFiles: Record<string, PackageFile[]> = { npm: [ { @@ -82,19 +84,61 @@ describe('workers/repository/errors-warnings', () => { ], }; - const res = getDepWarningsPR(packageFiles); + const res = getDepWarningsPR(packageFiles, dependencyDashboard); expect(res).toMatchInlineSnapshot(` " --- ### âš Dependency Lookup Warnings âš - Please correct - or verify that you can safely ignore - these lookup failures before you merge this PR. + Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. - - \`Warning 1\` - - \`Warning 2\` + " + `); + }); - Files affected: \`package.json\`, \`backend/package.json\`, \`Dockerfile\` + it('returns 2 pr warnings text dependencyDashboard false', () => { + const dependencyDashboard = false; + const packageFiles: Record<string, PackageFile[]> = { + npm: [ + { + packageFile: 'package.json', + deps: [ + { + warnings: [{ message: 'Warning 1', topic: '' }], + }, + {}, + ], + }, + { + packageFile: 'backend/package.json', + deps: [ + { + warnings: [{ message: 'Warning 1', topic: '' }], + }, + ], + }, + ], + dockerfile: [ + { + packageFile: 'Dockerfile', + deps: [ + { + warnings: [{ message: 'Warning 2', topic: '' }], + }, + ], + }, + ], + }; + + const res = getDepWarningsPR(packageFiles, dependencyDashboard); + expect(res).toMatchInlineSnapshot(` + " + --- + + ### âš Dependency Lookup Warnings âš + + Warnings were logged while processing this repo. Please check the logs for more information. " `); @@ -203,4 +247,56 @@ describe('workers/repository/errors-warnings', () => { expect(res).toBe(''); }); }); + + describe('getDepWarningsOnboardingPR()', () => { + it('returns onboarding warning text', () => { + const packageFiles: Record<string, PackageFile[]> = { + npm: [ + { + packageFile: 'package.json', + deps: [ + { + warnings: [{ message: 'Warning 1', topic: '' }], + }, + {}, + ], + }, + { + packageFile: 'backend/package.json', + deps: [ + { + warnings: [{ message: 'Warning 1', topic: '' }], + }, + ], + }, + ], + dockerfile: [ + { + packageFile: 'Dockerfile', + deps: [ + { + warnings: [{ message: 'Warning 2', topic: '' }], + }, + ], + }, + ], + }; + const res = getDepWarningsOnboardingPR(packageFiles); + expect(res).toMatchInlineSnapshot(` + " + --- + + ### âš Dependency Lookup Warnings âš + + Please correct - or verify that you can safely ignore - these lookup failures before you merge this PR. + + - \`Warning 1\` + - \`Warning 2\` + + Files affected: \`package.json\`, \`backend/package.json\`, \`Dockerfile\` + + " + `); + }); + }); }); diff --git a/lib/workers/repository/errors-warnings.ts b/lib/workers/repository/errors-warnings.ts index eefdd8fc4b885bf6422a0274c17e2d90a823133a..bc4e274eb928161117251d32188295d7d9d8e8ff 100644 --- a/lib/workers/repository/errors-warnings.ts +++ b/lib/workers/repository/errors-warnings.ts @@ -57,7 +57,7 @@ function getDepWarnings( return { warnings, warningFiles }; } -export function getDepWarningsPR( +export function getDepWarningsOnboardingPR( packageFiles: Record<string, PackageFile[]> ): string { const { warnings, warningFiles } = getDepWarnings(packageFiles); @@ -80,6 +80,28 @@ export function getDepWarningsPR( return warningText; } +export function getDepWarningsPR( + packageFiles: Record<string, PackageFile[]>, + dependencyDashboard?: boolean +): string { + const { warnings, warningFiles } = getDepWarnings(packageFiles); + let warningText = ''; + if (!warnings.length) { + return ''; + } + logger.debug({ warnings, warningFiles }, 'Found package lookup warnings'); + warningText = emojify( + `\n---\n\n### :warning: Dependency Lookup Warnings :warning:\n\n` + ); + warningText += 'Warnings were logged while processing this repo. '; + if (dependencyDashboard) { + warningText += `Please check the Dependency Dashboard for more information.\n\n`; + } else { + warningText += `Please check the logs for more information.\n\n`; + } + return warningText; +} + export function getDepWarningsDashboard( packageFiles: Record<string, PackageFile[]> ): string { diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index 905f564375987c159dfbe4874c8e6ce69d3dab98..1c1c41f35e2ee518f23f4a23cc83ef6d0345e782 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -14,7 +14,7 @@ import { import * as template from '../../../../util/template'; import type { BranchConfig } from '../../../types'; import { - getDepWarningsPR, + getDepWarningsOnboardingPR, getErrors, getWarnings, } from '../../errors-warnings'; @@ -115,7 +115,7 @@ If you need any further assistance then you can also [request help here](${ prBody = prBody.replace('{{CONFIG}}\n', configDesc); prBody = prBody.replace( '{{WARNINGS}}\n', - getWarnings(config) + getDepWarningsPR(packageFiles!) + getWarnings(config) + getDepWarningsOnboardingPR(packageFiles!) ); prBody = prBody.replace('{{ERRORS}}\n', getErrors(config)); prBody = prBody.replace('{{BASEBRANCH}}\n', getBaseBranchDesc(config)); diff --git a/lib/workers/repository/update/pr/body/index.spec.ts b/lib/workers/repository/update/pr/body/index.spec.ts index 91733d1e9fa1e27beee9dd56522ca2c72a014c07..00355c697cbef31c84bb99f621e2336f7f373350 100644 --- a/lib/workers/repository/update/pr/body/index.spec.ts +++ b/lib/workers/repository/update/pr/body/index.spec.ts @@ -1,4 +1,5 @@ import { mocked, platform } from '../../../../../../test/util'; +import type { PackageFile } from '../../../../../modules/manager/types'; import { prDebugDataRe } from '../../../../../modules/platform/pr-body'; import * as _template from '../../../../../util/template'; import * as _changelogs from './changelogs'; @@ -199,5 +200,54 @@ describe('workers/repository/update/pr/body/index', () => { const match = prDebugDataRe.exec(res); expect(match?.groups?.payload).toBeString(); }); + + it('pr body warning', async () => { + const massagedMarkDown = + '---\n\n### âš Dependency Lookup Warnings âš \n\n' + + 'Warnings were logged while processing this repo. ' + + 'Please check the Dependency Dashboard for more information\n\n---'; + + const compiledContent = + '---\n\n\n\n### âš Dependency Lookup Warnings âš ' + + '\n\n\n\nWarnings were logged while processing this repo. ' + + 'Please check the Dependency Dashboard for more information\n\n\n\n---'; + + platform.massageMarkdown.mockImplementation((x) => massagedMarkDown); + template.compile.mockImplementation((x) => compiledContent); + const packageFiles: Record<string, PackageFile[]> = { + npm: [ + { + packageFile: 'package.json', + deps: [ + { + warnings: [{ message: 'Warning 1', topic: '' }], + }, + {}, + ], + }, + ], + }; + + const res = await getPrBody( + { + manager: 'some-manager', + branchName: 'some-branch', + upgrades: [], + packageFiles: packageFiles, + prBodyTemplate: '{{{warnings}}}', + }, + { + debugData: { + updatedInVer: '1.2.3', + createdInVer: '1.2.3', + }, + } + ); + const expected = + '---\n\n### âš Dependency Lookup Warnings âš ' + + '\n\nWarnings were logged while processing this repo. ' + + 'Please check the Dependency Dashboard for more information\n\n---'; + expect(res).toBe(expected); + }); }); }); diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index 13a3fe90f35d41e5f50dd24cd5b146a4e3c3be89..a0c21528aa294dc3561a782617e6867cbc454349 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -4,6 +4,7 @@ import { toBase64 } from '../../../../../util/string'; import * as template from '../../../../../util/template'; import { joinUrlParts } from '../../../../../util/url'; import type { BranchConfig } from '../../../../types'; +import { getDepWarningsPR, getWarnings } from '../../../errors-warnings'; import { getChangelogs } from './changelogs'; import { getPrConfigDescription } from './config-description'; import { getControls } from './controls'; @@ -69,9 +70,18 @@ export async function getPrBody( prBodyConfig: PrBodyConfig ): Promise<string> { massageUpdateMetadata(branchConfig); + let warnings = ''; + warnings += getWarnings(branchConfig); + if (branchConfig.packageFiles) { + warnings += getDepWarningsPR( + branchConfig.packageFiles, + branchConfig.dependencyDashboard + ); + } const content = { header: getPrHeader(branchConfig), table: getPrUpdatesTable(branchConfig), + warnings, notes: getPrNotes(branchConfig) + getPrExtraNotes(branchConfig), changelogs: getChangelogs(branchConfig), configDescription: await getPrConfigDescription(branchConfig),