Skip to content

Commit

Permalink
feat(dashboard): show deprecated dependency warnings
Browse files Browse the repository at this point in the history
Closes #5098
  • Loading branch information
rarkins committed Jun 16, 2024
1 parent 32c9636 commit a6bb7a4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
32 changes: 32 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { BranchConfig, BranchUpgradeConfig } from '../types';
import * as dependencyDashboard from './dependency-dashboard';
import { getDashboardMarkdownVulnerabilities } from './dependency-dashboard';
import { PackageFiles } from './package-files';
import { clone } from '../../util/clone';

Check failure on line 27 in lib/workers/repository/dependency-dashboard.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../../util/clone` import should occur before import of `../../util/regex`

const createVulnerabilitiesMock = jest.fn();
jest.mock('./process/vulnerabilities', () => {
Expand Down Expand Up @@ -981,6 +982,37 @@ None detected
// same with dry run
await dryRun(branches, platform, 0, 1);
});

it('shows deprecations', async () => {
const branches: BranchConfig[] = [];
const packageFilesWithDeprecations = clone(packageFiles);
packageFilesWithDeprecations.npm[0].deps[0].deprecationMessage =
'some deprecation message';
packageFilesWithDeprecations.npm[0].deps[2].updates.push({
updateType: 'replacement',
newName: 'prop-types-tools',
newValue: '2.17.0',
branchName: 'renovate/airbnb-prop-types-replacement',
});
PackageFiles.add('main', packageFilesWithDeprecations);
await dependencyDashboard.ensureDependencyDashboard(
config,
branches,
packageFilesWithDeprecations,
);
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
expect(platform.ensureIssue.mock.calls[0][0].body).toInclude(
'The following dependencies are deprecated',
);
expect(platform.ensureIssue.mock.calls[0][0].body).toInclude(
'| npm | `cookie-parser` | ![Unavailable]',
);
expect(platform.ensureIssue.mock.calls[0][0].body).toInclude(
'npm | `express-handlebars` | ![Available]',
);
// same with dry run
await dryRun(branches, platform, 0, 1);
});
});

describe('multi base branch repo', () => {
Expand Down
42 changes: 41 additions & 1 deletion lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,29 @@ export async function ensureDependencyDashboard(
return;
}
logger.debug('Ensuring Dependency Dashboard');

// Check packageFiles for any deprecations
let hasDeprecations = false;
const deprecatedPackages: Record<string, Record<string, boolean>> = {};
logger.debug({ packageFiles }, 'Checking packageFiles for deprecations');
for (const [manager, fileNames] of Object.entries(packageFiles)) {
for (const fileName of fileNames) {
for (const dep of fileName.deps) {
const name = dep.packageName ?? dep.depName;
const hasReplacement = !!dep.updates?.find(
(updates) => updates.updateType === 'replacement',
);
if (name && (dep.deprecationMessage || hasReplacement)) {

Check failure on line 239 in lib/workers/repository/dependency-dashboard.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
hasDeprecations = true;
deprecatedPackages[manager] ??= {};
deprecatedPackages[manager][name] ??= hasReplacement;
}
}
}
}

const hasBranches = is.nonEmptyArray(branches);
if (config.dependencyDashboardAutoclose && !hasBranches) {
if (config.dependencyDashboardAutoclose && !hasBranches && !hasDeprecations) {
if (GlobalConfig.get('dryRun')) {
logger.info(
{ title: config.dependencyDashboardTitle },
Expand All @@ -245,6 +266,25 @@ export async function ensureDependencyDashboard(

issueBody = appendRepoProblems(config, issueBody);

if (hasDeprecations) {
issueBody += '> [!WARNING]\n';
issueBody += 'The following dependencies are deprecated:\n\n';
issueBody += '| Datasource | Name | Replacement? |\n';
issueBody += '|------------|------|--------------|\n';
for (const manager of Object.keys(deprecatedPackages).sort()) {
const deps = deprecatedPackages[manager];
for (const depName of Object.keys(deps).sort()) {
const hasReplacement = deps[depName];
issueBody += `| ${manager} | \`${depName}\` | ${
hasReplacement
? '![Available](https://img.shields.io/badge/available-green?style=flat-square)'
: '![Unavailable](https://img.shields.io/badge/unavailable-orange?style=flat-square)'
} |\n`;
}
}
issueBody += '\n';
}

const pendingApprovals = branches.filter(
(branch) => branch.result === 'needs-approval',
);
Expand Down

0 comments on commit a6bb7a4

Please sign in to comment.