Skip to content

Commit

Permalink
fix(config): Making suppression notification work for PR and onboardi…
Browse files Browse the repository at this point in the history
…ngPR for consistency (#22831)
  • Loading branch information
MojoJojo86 authored Jun 21, 2023
1 parent 8fa7a9d commit ae8bb71
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
30 changes: 26 additions & 4 deletions lib/workers/repository/errors-warnings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('workers/repository/errors-warnings', () => {
});

it('returns 2 pr warnings text dependencyDashboard true', () => {
const config: RenovateConfig = {};
const dependencyDashboard = true;
const packageFiles: Record<string, PackageFile[]> = {
npm: [
Expand Down Expand Up @@ -84,7 +85,7 @@ describe('workers/repository/errors-warnings', () => {
],
};

const res = getDepWarningsPR(packageFiles, dependencyDashboard);
const res = getDepWarningsPR(packageFiles, config, dependencyDashboard);
expect(res).toMatchInlineSnapshot(`
"
---
Expand All @@ -98,6 +99,7 @@ describe('workers/repository/errors-warnings', () => {
});

it('returns 2 pr warnings text dependencyDashboard false', () => {
const config: RenovateConfig = {};
const dependencyDashboard = false;
const packageFiles: Record<string, PackageFile[]> = {
npm: [
Expand Down Expand Up @@ -131,7 +133,7 @@ describe('workers/repository/errors-warnings', () => {
],
};

const res = getDepWarningsPR(packageFiles, dependencyDashboard);
const res = getDepWarningsPR(packageFiles, config, dependencyDashboard);
expect(res).toMatchInlineSnapshot(`
"
---
Expand All @@ -145,8 +147,18 @@ describe('workers/repository/errors-warnings', () => {
});

it('PR warning returns empty string', () => {
const config: RenovateConfig = {};
const packageFiles: Record<string, PackageFile[]> = {};
const res = getDepWarningsPR(packageFiles, config);
expect(res).toBe('');
});

it('suppress notifications contains dependencyLookupWarnings flag then return empty string', () => {
const config: RenovateConfig = {
suppressNotifications: ['dependencyLookupWarnings'],
};
const packageFiles: Record<string, PackageFile[]> = {};
const res = getDepWarningsPR(packageFiles);
const res = getDepWarningsPR(packageFiles, config);
expect(res).toBe('');
});
});
Expand Down Expand Up @@ -261,6 +273,7 @@ describe('workers/repository/errors-warnings', () => {

describe('getDepWarningsOnboardingPR()', () => {
it('returns onboarding warning text', () => {
const config: RenovateConfig = {};
const packageFiles: Record<string, PackageFile[]> = {
npm: [
{
Expand Down Expand Up @@ -292,7 +305,7 @@ describe('workers/repository/errors-warnings', () => {
},
],
};
const res = getDepWarningsOnboardingPR(packageFiles);
const res = getDepWarningsOnboardingPR(packageFiles, config);
expect(res).toMatchInlineSnapshot(`
"
---
Expand All @@ -309,5 +322,14 @@ describe('workers/repository/errors-warnings', () => {
"
`);
});

it('suppress notifications contains dependencyLookupWarnings flag then return empty string', () => {
const config: RenovateConfig = {
suppressNotifications: ['dependencyLookupWarnings'],
};
const packageFiles: Record<string, PackageFile[]> = {};
const res = getDepWarningsOnboardingPR(packageFiles, config);
expect(res).toBe('');
});
});
});
10 changes: 9 additions & 1 deletion lib/workers/repository/errors-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ function getDepWarnings(
}

export function getDepWarningsOnboardingPR(
packageFiles: Record<string, PackageFile[]>
packageFiles: Record<string, PackageFile[]>,
config: RenovateConfig
): string {
const { warnings, warningFiles } = getDepWarnings(packageFiles);
if (config.suppressNotifications?.includes('dependencyLookupWarnings')) {
return '';
}
let warningText = '';
if (!warnings.length) {
return '';
Expand All @@ -83,9 +87,13 @@ export function getDepWarningsOnboardingPR(

export function getDepWarningsPR(
packageFiles: Record<string, PackageFile[]>,
config: RenovateConfig,
dependencyDashboard?: boolean
): string {
const { warnings, warningFiles } = getDepWarnings(packageFiles);
if (config.suppressNotifications?.includes('dependencyLookupWarnings')) {
return '';
}
let warningText = '';
if (!warnings.length) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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) + getDepWarningsOnboardingPR(packageFiles!)
getWarnings(config) + getDepWarningsOnboardingPR(packageFiles!, config)
);
prBody = prBody.replace('{{ERRORS}}\n', getErrors(config));
prBody = prBody.replace('{{BASEBRANCH}}\n', getBaseBranchDesc(config));
Expand Down
21 changes: 14 additions & 7 deletions lib/workers/repository/update/pr/body/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);
expect(res).toBeEmptyString();
});
Expand Down Expand Up @@ -94,7 +95,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);

expect(upgrade).toMatchObject({
Expand Down Expand Up @@ -132,7 +134,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);

expect(upgrade).toMatchObject({
Expand Down Expand Up @@ -160,7 +163,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);
expect(res).toContain('PR BODY');
expect(res).toContain(`<!--renovate-debug`);
Expand All @@ -184,7 +188,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);
expect(res).toContain(['aaa', '**Rebasing**: BAR', 'bbb'].join('\n'));
});
Expand All @@ -206,7 +211,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);

const match = prDebugDataRe.exec(res);
Expand Down Expand Up @@ -255,7 +261,8 @@ describe('workers/repository/update/pr/body/index', () => {
createdInVer: '1.2.3',
targetBranch: 'base',
},
}
},
{}
);
const expected =
'---\n\n### ⚠ Dependency Lookup Warnings ⚠' +
Expand Down
5 changes: 4 additions & 1 deletion lib/workers/repository/update/pr/body/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { RenovateConfig } from '../../../../../config/types';
import { PrDebugData, platform } from '../../../../../modules/platform';
import { regEx } from '../../../../../util/regex';
import { toBase64 } from '../../../../../util/string';
Expand Down Expand Up @@ -67,14 +68,16 @@ const rebasingRegex = regEx(/\*\*Rebasing\*\*: .*/);

export function getPrBody(
branchConfig: BranchConfig,
prBodyConfig: PrBodyConfig
prBodyConfig: PrBodyConfig,
config: RenovateConfig
): string {
massageUpdateMetadata(branchConfig);
let warnings = '';
warnings += getWarnings(branchConfig);
if (branchConfig.packageFiles) {
warnings += getDepWarningsPR(
branchConfig.packageFiles,
config,
branchConfig.dependencyDashboard
);
}
Expand Down
16 changes: 10 additions & 6 deletions lib/workers/repository/update/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,16 @@ export async function ensurePr(
}
}

const prBody = getPrBody(config, {
debugData: updatePrDebugData(
config.baseBranch,
existingPr?.bodyStruct?.debugData
),
});
const prBody = getPrBody(
config,
{
debugData: updatePrDebugData(
config.baseBranch,
existingPr?.bodyStruct?.debugData
),
},
config
);

try {
if (existingPr) {
Expand Down

0 comments on commit ae8bb71

Please sign in to comment.