Skip to content

Commit

Permalink
fix(datasource): centralize lookupName check (#5661)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 7, 2020
1 parent aa1d865 commit 8ac0f57
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 52 deletions.
6 changes: 0 additions & 6 deletions lib/datasource/cdnjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export async function getDigest(
export async function getPkgReleases({
lookupName,
}: Partial<GetReleasesConfig>): Promise<ReleaseResult | null> {
// istanbul ignore if
if (!lookupName) {
logger.warn('CDNJS lookup failure: empty lookupName');
return null;
}

const [library, ...assetParts] = lookupName.split('/');
const assetName = assetParts.join('/');

Expand Down
7 changes: 0 additions & 7 deletions lib/datasource/crate/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,5 @@ describe('datasource/crate', () => {
const res = await getPkgReleases({ lookupName: 'some_crate' });
expect(res).toBeNull();
});
it('returns null if lookupName is undefined', async () => {
got.mockReturnValueOnce({
body: res1,
});
const res = await getPkgReleases({ lookupName: undefined });
expect(res).toBeNull();
});
});
});
4 changes: 0 additions & 4 deletions lib/datasource/crate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export const id = 'crate';
export async function getPkgReleases({
lookupName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
if (!lookupName) {
return null;
}

const cacheNamespace = 'datasource-crate';
const cacheKey = lookupName;
const cachedResult = await renovateCache.get<ReleaseResult>(
Expand Down
7 changes: 0 additions & 7 deletions lib/datasource/galaxy/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,5 @@ describe('datasource/galaxy', () => {
const res = await getPkgReleases({ lookupName: 'foo.bar' });
expect(res).toBeNull();
});
it('returns null if lookupName is undefined', async () => {
got.mockReturnValueOnce({
body: res1,
});
const res = await getPkgReleases({ lookupName: undefined });
expect(res).toBeNull();
});
});
});
4 changes: 0 additions & 4 deletions lib/datasource/galaxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export const id = 'galaxy';
export async function getPkgReleases({
lookupName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
if (!lookupName) {
return null;
}

const cacheNamespace = 'datasource-galaxy';
const cacheKey = lookupName;
const cachedResult = await renovateCache.get<ReleaseResult>(
Expand Down
4 changes: 0 additions & 4 deletions lib/datasource/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ export async function getPkgReleases({
lookupName,
registryUrls,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
if (!lookupName) {
logger.warn(`lookupName was not provided to getPkgReleases`);
return null;
}
const [helmRepository] = registryUrls;
if (!helmRepository) {
logger.warn(`helmRepository was not provided to getPkgReleases`);
Expand Down
6 changes: 0 additions & 6 deletions lib/datasource/hex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ interface HexRelease {
export async function getPkgReleases({
lookupName,
}: Partial<GetReleasesConfig>): Promise<ReleaseResult | null> {
// istanbul ignore if
if (!lookupName) {
logger.warn('hex lookup failure: No lookupName');
return null;
}

// Get dependency name from lookupName.
// If the dependency is private lookupName contains organization name as following:
// hexPackageName:organizationName
Expand Down
7 changes: 7 additions & 0 deletions lib/datasource/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ describe('datasource/index', () => {
})
).toBeNull();
});
it('returns null for no lookupName', async () => {
expect(
await datasource.getPkgReleases({
datasource: 'npm',
})
).toBeNull();
});
it('returns null for unknown datasource', async () => {
expect(
await datasource.getPkgReleases({
Expand Down
4 changes: 4 additions & 0 deletions lib/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export async function getPkgReleases(
): Promise<ReleaseResult | null> {
const { datasource } = config;
const lookupName = config.lookupName || config.depName;
if (!lookupName) {
logger.error({ config }, 'Datasource getPkgReleases without lookupName');
return null;
}
let res;
try {
res = await getRawReleases({
Expand Down
9 changes: 0 additions & 9 deletions lib/datasource/pod/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { api as _api } from '../../platform/github/gh-got-wrapper';
import { getPkgReleases } from '.';
import { mocked } from '../../../test/util';
import { GotResponse } from '../../platform';
import { GetReleasesConfig } from '../common';

const api = mocked(_api);

Expand All @@ -18,14 +17,6 @@ describe('datasource/cocoapods', () => {
beforeEach(() => global.renovateCache.rmAll());
it('returns null for invalid inputs', async () => {
api.get.mockResolvedValueOnce(null);
expect(
await getPkgReleases({ registryUrls: [] } as GetReleasesConfig)
).toBeNull();
expect(
await getPkgReleases({
lookupName: null,
})
).toBeNull();
expect(
await getPkgReleases({
lookupName: 'foobar',
Expand Down
5 changes: 0 additions & 5 deletions lib/datasource/pod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ export async function getPkgReleases(
registryUrls =
registryUrls && registryUrls.length ? registryUrls : [defaultCDN];

if (!lookupName) {
logger.debug(config, `CocoaPods: invalid lookup name`);
return null;
}

const podName = lookupName.replace(/\/.*$/, '');

const cachedResult = await renovateCache.get<ReleaseResult>(
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ describe('workers/repository/process/lookup', () => {
expect(res).toMatchSnapshot();
});
it('handles git submodule update', async () => {
config.depName = 'some-path';
config.versioning = gitVersioning.id;
config.datasource = datasourceGitSubmodules.id;
gitSubmodules.getPkgReleases.mockResolvedValueOnce({
Expand Down

0 comments on commit 8ac0f57

Please sign in to comment.