Skip to content

Commit

Permalink
feat(datasource/conda): support custom registries (#17809)
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Oct 5, 2022
1 parent 87910eb commit 699a5cf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`modules/datasource/conda/index getReleases processes real data 1`] = `
{
"homepage": "http://anaconda.org/anaconda/pytest",
"registryUrl": "https://api.anaconda.org/package/",
"registryUrl": "https://api.anaconda.org/package",
"releases": [
{
"version": "2.3.3",
Expand Down
48 changes: 48 additions & 0 deletions lib/modules/datasource/conda/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock';
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
import { datasource, defaultRegistryUrl } from './common';
import { CondaDatasource } from './index';

const depName = 'main/pytest';
const depUrl = `/${depName}`;
Expand Down Expand Up @@ -61,5 +62,52 @@ describe('modules/datasource/conda/index', () => {
expect(res).toMatchSnapshot();
expect(res?.releases).toHaveLength(94);
});

it('returns null without registryUrl', async () => {
const condaDatasource = new CondaDatasource();
const res = await condaDatasource.getReleases({
registryUrl: '',
packageName: depName,
});
expect(res).toBeNull();
});

it('supports multiple custom datasource urls', async () => {
const depName = 'pytest';
httpMock
.scope('https://api.anaconda.org/package/rapids')
.get(`/${depName}`)
.reply(404);
httpMock
.scope('https://api.anaconda.org/package/conda-forge')
.get(`/${depName}`)
.reply(200, {
html_url: 'http://anaconda.org/anaconda/pytest',
dev_url: 'https://github.com/pytest-dev/pytest/',
versions: ['2.7.0', '2.5.1', '2.6.0'],
});
const config = {
registryUrls: [
'https://api.anaconda.org/package/rapids',
'https://api.anaconda.org/package/conda-forge',
'https://api.anaconda.org/package/nvidia',
],
};
const res = await getPkgReleases({
...config,
datasource,
depName,
});
expect(res).toMatchObject({
homepage: 'http://anaconda.org/anaconda/pytest',
registryUrl: 'https://api.anaconda.org/package/conda-forge',
releases: [
{ version: '2.5.1' },
{ version: '2.6.0' },
{ version: '2.7.0' },
],
sourceUrl: 'https://github.com/pytest-dev/pytest',
});
});
});
});
13 changes: 9 additions & 4 deletions lib/modules/datasource/conda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { cache } from '../../../util/cache/package/decorator';
import { HttpError } from '../../../util/http';
import { joinUrlParts } from '../../../util/url';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
import { datasource, defaultRegistryUrl } from './common';
Expand All @@ -14,7 +15,9 @@ export class CondaDatasource extends Datasource {
super(datasource);
}

override readonly customRegistrySupport = false;
override readonly customRegistrySupport = true;

override readonly registryStrategy = 'hunt';

override readonly defaultRegistryUrls = [defaultRegistryUrl];

Expand All @@ -33,9 +36,11 @@ export class CondaDatasource extends Datasource {
}: GetReleasesConfig): Promise<ReleaseResult | null> {
logger.trace({ registryUrl, packageName }, 'fetching conda package');

// TODO: types (#7154)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const url = `${registryUrl}${packageName}`;
if (!registryUrl) {
return null;
}

const url = joinUrlParts(registryUrl, packageName);

const result: ReleaseResult = {
releases: [],
Expand Down

0 comments on commit 699a5cf

Please sign in to comment.