Skip to content

Commit

Permalink
feat(dashboard): include dependency lookup warnings (#16297)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaronHatoum authored Aug 2, 2022
1 parent a251fc4 commit dd5ca94
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() checks detected dependencies section dependency dashboard lookup warnings Dependency Lookup Warnings message in issues body 1`] = `
"This issue lists Renovate updates and detected dependencies. Read the [Dependency Dashboard](https://docs.renovatebot.com/key-concepts/dashboard/) docs to learn more.
---
### ⚠ Dependency Lookup Warnings ⚠
- Renovate failed to look up the following dependencies: \`dependency-2\`.
Files affected: \`package.json\`
---
This repository currently has no open or pending branches.
## Detected dependencies
<details><summary>Branch main</summary>
<blockquote>
<details><summary>npm</summary>
<blockquote>
<details><summary>package.json</summary>
</details>
</blockquote>
</details>
</blockquote>
</details>
<details><summary>Branch dev</summary>
<blockquote>
<details><summary>dockerfile</summary>
<blockquote>
<details><summary>Dockerfile</summary>
- \`ubuntu 20.04\`
</details>
</blockquote>
</details>
<details><summary>npm</summary>
<blockquote>
<details><summary>package.json</summary>
- \`cookie-parser ^1.4.5\`
- \`express ~4.17.1\`
- \`express-handlebars >=5.3.4\`
- \`geoip-lite 1.4.*\`
- \`nodemailer 6.7.0\`
- \`redis 3.1.2-3.4.0\`
- \`dotenv 10.0.0\`
- \`nodemon 2.0.14\`
</details>
</blockquote>
</details>
<details><summary>poetry</summary>
<blockquote>
<details><summary>pyproject.toml</summary>
- \`six <=1.3.0\`
</details>
</blockquote>
</details>
</blockquote>
</details>
"
`;

exports[`workers/repository/dependency-dashboard ensureDependencyDashboard() checks detected dependencies section multi base branch repo add detected dependencies to the Dependency Dashboard body 1`] = `
"This issue lists Renovate updates and detected dependencies. Read the [Dependency Dashboard](https://docs.renovatebot.com/key-concepts/dashboard/) docs to learn more.
Expand Down
35 changes: 35 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,41 @@ describe('workers/repository/dependency-dashboard', () => {
await dryRun(branches, platform);
});
});

describe('dependency dashboard lookup warnings', () => {
beforeEach(() => {
PackageFiles.add('main', packageFiles);
PackageFiles.add('dev', packageFiles);
});

afterEach(() => {
PackageFiles.clear();
});

it('Dependency Lookup Warnings message in issues body', async () => {
const branches: BranchConfig[] = [];
PackageFiles.add('main', {
npm: [{ packageFile: 'package.json', deps: [] }],
});
const dep = [
{
warnings: [{ message: 'dependency-2', topic: '' }],
},
];
const packageFiles: Record<string, PackageFile[]> = {
npm: [{ packageFile: 'package.json', deps: dep }],
};
await dependencyDashboard.ensureDependencyDashboard(
config,
branches,
packageFiles
);
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
// same with dry run
await dryRun(branches, platform);
});
});
});
});
});
12 changes: 11 additions & 1 deletion lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { nameFromLevel } from 'bunyan';
import { GlobalConfig } from '../../config/global';
import type { RenovateConfig } from '../../config/types';
import { getProblems, logger } from '../../logger';
import type { PackageFile } from '../../modules/manager/types';
import { platform } from '../../modules/platform';
import { regEx } from '../../util/regex';
import * as template from '../../util/template';
import { BranchConfig, BranchResult, SelectAllConfig } from '../types';
import { getDepWarningsDashboard } from './errors-warnings';
import { PackageFiles } from './package-files';

interface DependencyDashboard {
Expand Down Expand Up @@ -102,7 +104,8 @@ function appendRepoProblems(config: RenovateConfig, issueBody: string): string {

export async function ensureDependencyDashboard(
config: SelectAllConfig,
allBranches: BranchConfig[]
allBranches: BranchConfig[],
packageFiles: Record<string, PackageFile[]> = {}
): Promise<void> {
// legacy/migrated issue
const reuseTitle = 'Update Dependencies (Renovate Bot)';
Expand Down Expand Up @@ -256,6 +259,13 @@ export async function ensureDependencyDashboard(
}
issueBody += '\n';
}

const warn = getDepWarningsDashboard(packageFiles);
if (warn) {
issueBody += warn;
issueBody += '\n';
}

const otherRes = [
BranchResult.Pending,
BranchResult.NeedsApproval,
Expand Down
68 changes: 67 additions & 1 deletion lib/workers/repository/errors-warnings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { RenovateConfig, getConfig } from '../../../test/util';
import type { PackageFile } from '../../modules/manager/types';
import { getDepWarningsPR, getErrors, getWarnings } from './errors-warnings';
import {
getDepWarningsDashboard,
getDepWarningsPR,
getErrors,
getWarnings,
} from './errors-warnings';

describe('workers/repository/errors-warnings', () => {
describe('getWarnings()', () => {
Expand Down Expand Up @@ -102,6 +107,67 @@ describe('workers/repository/errors-warnings', () => {
});
});

describe('getDepWarningsDashboard()', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('returns dependency dashboard warning text', () => {
const packageFiles: Record<string, PackageFile[]> = {
npm: [
{
packageFile: 'package.json',
deps: [
{
warnings: [{ message: 'dependency-1', topic: '' }],
},
{},
],
},
{
packageFile: 'backend/package.json',
deps: [
{
warnings: [{ message: 'dependency-1', topic: '' }],
},
],
},
],
dockerfile: [
{
packageFile: 'Dockerfile',
deps: [
{
warnings: [{ message: 'dependency-2', topic: '' }],
},
],
},
],
};
const res = getDepWarningsDashboard(packageFiles);
expect(res).toMatchInlineSnapshot(`
"
---
### ⚠ Dependency Lookup Warnings ⚠
- Renovate failed to look up the following dependencies: \`dependency-1\`, \`dependency-2\`.
Files affected: \`package.json\`, \`backend/package.json\`, \`Dockerfile\`
---
"
`);
});

it('dependency dashboard warning returns empty string', () => {
const packageFiles: Record<string, PackageFile[]> = {};
const res = getDepWarningsDashboard(packageFiles);
expect(res).toBe('');
});
});

describe('getErrors()', () => {
let config: RenovateConfig;

Expand Down
30 changes: 26 additions & 4 deletions lib/workers/repository/errors-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ export function getDepWarningsPR(
if (!warnings.length) {
return '';
}
logger.debug(
{ warnings, warningFiles },
'Found package lookup warnings in onboarding'
);
logger.debug({ warnings, warningFiles }, 'Found package lookup warnings');
warningText = emojify(
`\n---\n\n### :warning: Dependency Lookup Warnings :warning:\n\n`
);
Expand All @@ -82,3 +79,28 @@ export function getDepWarningsPR(
'\n\n';
return warningText;
}

export function getDepWarningsDashboard(
packageFiles: Record<string, PackageFile[]>
): string {
const { warnings, warningFiles } = getDepWarnings(packageFiles);
if (!warnings.length) {
return '';
}

const depWarnings = warnings
.map((w) => w.replace('Failed to look up dependency ', ''))
.map((dep) => '`' + dep + '`')
.join(', ');

logger.debug({ warnings, warningFiles }, 'Found package lookup warnings');
let warningText = emojify(
`\n---\n\n### :warning: Dependency Lookup Warnings :warning:\n\n`
);
warningText += `- Renovate failed to look up the following dependencies: `;
warningText += depWarnings;
warningText += '.\n\nFiles affected: ';
warningText += warningFiles.map((f) => '`' + f + '`').join(', ');
warningText += '\n\n---\n\n';
return warningText;
}
2 changes: 1 addition & 1 deletion lib/workers/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function renovateRepository(
}
logger.debug(`Automerged but already retried once`);
} else {
await ensureDependencyDashboard(config, branches);
await ensureDependencyDashboard(config, branches, packageFiles);
}
await finaliseRepo(config, branchList);
// TODO #7154
Expand Down

0 comments on commit dd5ca94

Please sign in to comment.