Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(platform): optional getVulnerabilityAlerts #21449

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions lib/modules/platform/azure/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,13 +1349,6 @@ describe('modules/platform/azure/index', () => {
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty', async () => {
const res = await azure.getVulnerabilityAlerts();
expect(res).toHaveLength(0);
});
});

describe('deleteLabel()', () => {
it('Should delete a label', async () => {
await initRepo({ repository: 'some/repo' });
Expand Down
6 changes: 1 addition & 5 deletions lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
REPOSITORY_NOT_FOUND,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, VulnerabilityAlert } from '../../../types';
import type { BranchStatus } from '../../../types';
import * as git from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
Expand Down Expand Up @@ -909,7 +909,3 @@ export async function deleteLabel(
const azureApiGit = await azureApi.gitApi();
await azureApiGit.deletePullRequestLabels(config.repoId, prNumber, label);
}

export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
return Promise.resolve([]);
}
7 changes: 0 additions & 7 deletions lib/modules/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1729,13 +1729,6 @@ Followed by some information.
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty array', async () => {
expect.assertions(1);
expect(await bitbucket.getVulnerabilityAlerts()).toEqual([]);
});
});

describe('getBranchStatus()', () => {
it('should be success', async () => {
const scope = await initRepo();
Expand Down
7 changes: 1 addition & 6 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
REPOSITORY_NOT_FOUND,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, VulnerabilityAlert } from '../../../types';
import type { BranchStatus } from '../../../types';
import type { FileData } from '../../../types/platform/bitbucket-server';
import * as git from '../../../util/git';
import { deleteBranch } from '../../../util/git';
Expand Down Expand Up @@ -979,8 +979,3 @@ export function massageMarkdown(input: string): string {
.replace(regEx(`\n---\n\n.*?<!-- rebase-check -->.*?(\n|$)`), '')
.replace(regEx('<!--.*?-->', 'g'), '');
}

export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
logger.debug(`getVulnerabilityAlerts()`);
return Promise.resolve([]);
}
6 changes: 0 additions & 6 deletions lib/modules/platform/bitbucket/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1456,12 +1456,6 @@ describe('modules/platform/bitbucket/index', () => {
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty array', async () => {
expect(await bitbucket.getVulnerabilityAlerts()).toEqual([]);
});
});

describe('getJsonFile()', () => {
it('returns file content', async () => {
const data = { foo: 'bar' };
Expand Down
6 changes: 1 addition & 5 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import is from '@sindresorhus/is';
import JSON5 from 'json5';
import { REPOSITORY_NOT_FOUND } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, VulnerabilityAlert } from '../../../types';
import type { BranchStatus } from '../../../types';
import * as git from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { BitbucketHttp, setBaseUrl } from '../../../util/http/bitbucket';
Expand Down Expand Up @@ -949,7 +949,3 @@ export async function mergePr({
}
return true;
}

export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
return Promise.resolve([]);
}
7 changes: 1 addition & 6 deletions lib/modules/platform/codecommit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
REPOSITORY_NOT_FOUND,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, PrState, VulnerabilityAlert } from '../../../types';
import type { BranchStatus, PrState } from '../../../types';
import * as git from '../../../util/git';
import { regEx } from '../../../util/regex';
import { sanitize } from '../../../util/sanitize';
Expand Down Expand Up @@ -563,11 +563,6 @@ export function deleteLabel(prNumber: number, label: string): Promise<void> {
return Promise.resolve();
}

/* istanbul ignore next */
export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
return Promise.resolve([]);
}

// Returns the combined status for a branch.
/* istanbul ignore next */
export function getBranchStatus(branchName: string): Promise<BranchStatus> {
Expand Down
6 changes: 0 additions & 6 deletions lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1916,12 +1916,6 @@ describe('modules/platform/gitea/index', () => {
});
});

describe('getVulnerabilityAlerts', () => {
it('should return an empty list - unsupported by platform', async () => {
expect(await gitea.getVulnerabilityAlerts()).toEqual([]);
});
});

describe('getJsonFile()', () => {
it('returns file content', async () => {
const data = { foo: 'bar' };
Expand Down
7 changes: 1 addition & 6 deletions lib/modules/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
REPOSITORY_MIRRORED,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, VulnerabilityAlert } from '../../../types';
import type { BranchStatus } from '../../../types';
import * as git from '../../../util/git';
import { setBaseUrl } from '../../../util/http/gitea';
import { sanitize } from '../../../util/sanitize';
Expand Down Expand Up @@ -949,10 +949,6 @@ const platform: Platform = {
massageMarkdown(prBody: string): string {
return smartTruncate(smartLinks(prBody), 1000000);
},

getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
return Promise.resolve([]);
},
};

/* eslint-disable @typescript-eslint/unbound-method */
Expand All @@ -979,7 +975,6 @@ export const {
getPrList,
getRepoForceRebase,
getRepos,
getVulnerabilityAlerts,
initPlatform,
initRepo,
mergePr,
Expand Down
7 changes: 0 additions & 7 deletions lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2139,13 +2139,6 @@ These updates have all been created already. Click a checkbox below to force a r
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty', async () => {
const res = await gitlab.getVulnerabilityAlerts();
expect(res).toHaveLength(0);
});
});

describe('deleteLabel(issueNo, label)', () => {
it('should delete the label', async () => {
httpMock
Expand Down
6 changes: 1 addition & 5 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TEMPORARY_ERROR,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { BranchStatus, VulnerabilityAlert } from '../../../types';
import type { BranchStatus } from '../../../types';
import * as git from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { setBaseUrl } from '../../../util/http/gitlab';
Expand Down Expand Up @@ -1209,10 +1209,6 @@ export async function ensureCommentRemoval(
}
}

export function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
return Promise.resolve([]);
}

export async function filterUnavailableUsers(
users: string[]
): Promise<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface Platform {
findIssue(title: string): Promise<Issue | null>;
getIssueList(): Promise<Issue[]>;
getIssue?(number: number, useCache?: boolean): Promise<Issue | null>;
getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]>;
getVulnerabilityAlerts?(): Promise<VulnerabilityAlert[]>;
getRawFile(
fileName: string,
repoName?: string,
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/init/vulnerability.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('workers/repository/init/vulnerability', () => {
config.transitiveRemediation = true;
// TODO #7154
delete config.vulnerabilityAlerts!.enabled;
delete config.packageRules; // test coverage
platform.getVulnerabilityAlerts.mockResolvedValue([
partial<VulnerabilityAlert>(),
{
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/vulnerability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export async function detectVulnerabilityAlerts(
logger.debug('Vulnerability alerts are disabled');
return input;
}
const alerts = await platform.getVulnerabilityAlerts();
if (!alerts.length) {
const alerts = await platform.getVulnerabilityAlerts?.();
if (!alerts?.length) {
logger.debug('No vulnerability alerts found');
if (input.vulnerabilityAlertsOnly) {
throw new Error(NO_VULNERABILITY_ALERTS);
Expand Down