From c74164953045647ebbd21034e01968d1c712d534 Mon Sep 17 00:00:00 2001 From: Maron <98313426+MaronHatoum@users.noreply.github.com> Date: Mon, 12 Sep 2022 12:08:45 +0300 Subject: [PATCH] feat: show warning in pr body (#17609) --- lib/config/options/index.ts | 2 +- .../repository/errors-warnings.spec.ts | 108 +++++++++++++++++- lib/workers/repository/errors-warnings.ts | 24 +++- lib/workers/repository/onboarding/pr/index.ts | 4 +- .../repository/update/pr/body/index.spec.ts | 50 ++++++++ .../repository/update/pr/body/index.ts | 10 ++ 6 files changed, 188 insertions(+), 10 deletions(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 2dac6716d2..865d7a63b2 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 80f40e1962..8fbb5ba784 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 eefdd8fc4b..bc4e274eb9 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 905f564375..1c1c41f35e 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 91733d1e9f..00355c697c 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 13a3fe90f3..a0c21528aa 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), -- GitLab