renovate/lib/modules/datasource/conda/index.ts

79 lines
2.2 KiB
TypeScript

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';
import type { CondaPackage } from './types';
export class CondaDatasource extends Datasource {
static readonly id = datasource;
constructor() {
super(datasource);
}
override readonly customRegistrySupport = true;
override readonly registryStrategy = 'hunt';
override readonly defaultRegistryUrls = [defaultRegistryUrl];
override readonly caching = true;
override readonly sourceUrlSupport = 'package';
override readonly sourceUrlNote =
'The source URL is determined from the `dev_url` field in the results.';
@cache({
namespace: `datasource-${datasource}`,
key: ({ registryUrl, packageName }: GetReleasesConfig) =>
// TODO: types (#22198)
`${registryUrl}:${packageName}`,
})
async getReleases({
registryUrl,
packageName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
logger.trace({ registryUrl, packageName }, 'fetching conda package');
if (!registryUrl) {
return null;
}
const url = joinUrlParts(registryUrl, packageName);
const result: ReleaseResult = {
releases: [],
};
let response: { body: CondaPackage };
try {
response = await this.http.getJson(url);
result.homepage = response.body.html_url;
result.sourceUrl = response.body.dev_url;
response.body.versions.forEach((version: string) => {
const thisRelease: Release = {
version,
};
result.releases.push(thisRelease);
});
} catch (err) {
// istanbul ignore else: not testable with nock
if (err instanceof HttpError) {
if (err.response?.statusCode !== 404) {
throw new ExternalHostError(err);
}
}
this.handleGenericErrors(err);
}
return result.releases.length ? result : null;
}
}