Skip to content

Commit

Permalink
refactor: customRegistrySupport (#9142)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 15, 2021
1 parent 6ebe8ba commit f1a4102
Show file tree
Hide file tree
Showing 33 changed files with 46 additions and 43 deletions.
1 change: 1 addition & 0 deletions lib/datasource/bitbucket-tags/index.ts
Expand Up @@ -8,6 +8,7 @@ import { BitbucketCommit, BitbucketTag } from './types';
const bitbucketHttp = new BitbucketHttp();

export const id = 'bitbucket-tags';
export const customRegistrySupport = true;
export const registryStrategy = 'first';
export const defaultRegistryUrls = ['https://bitbucket.org'];

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/cdnjs/index.ts
Expand Up @@ -3,7 +3,7 @@ import { Http } from '../../util/http';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'cdnjs';
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;
export const defaultRegistryUrls = ['https://api.cdnjs.com/'];
export const caching = true;

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/clojure/index.ts
@@ -1,7 +1,7 @@
import { MAVEN_REPO } from '../maven/common';

export const id = 'clojure';

export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://clojars.org/repo', MAVEN_REPO];
export const registryStrategy = 'merge';

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/crate/index.ts
Expand Up @@ -12,6 +12,7 @@ import * as cargoVersioning from '../../versioning/cargo';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';

export const id = 'crate';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://crates.io'];
export const defaultVersioning = cargoVersioning.id;
export const registryStrategy = 'first';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/dart/index.ts
Expand Up @@ -4,7 +4,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'dart';
export const defaultRegistryUrls = ['https://pub.dartlang.org/'];
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;

const http = new Http(id);

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/docker/index.ts
Expand Up @@ -20,6 +20,7 @@ import { Image, ImageList, MediaType } from './types';
// TODO: replace www-authenticate with https://www.npmjs.com/package/auth-header ?

export const id = 'docker';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://index.docker.io'];
export const defaultVersioning = dockerVersioning.id;
export const registryStrategy = 'first';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/galaxy/index.ts
Expand Up @@ -6,7 +6,7 @@ import type { GetReleasesConfig, Release, ReleaseResult } from '../types';

export const id = 'galaxy';
export const defaultRegistryUrls = ['https://galaxy.ansible.com/'];
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;

const http = new Http(id);

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/git-refs/index.ts
Expand Up @@ -4,7 +4,7 @@ import * as semver from '../../versioning/semver';
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'git-refs';
export const registryUrlRestriction = 'disallowed';
export const customRegistrySupport = false;

const cacheMinutes = 10;

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/git-tags/index.ts
Expand Up @@ -3,7 +3,7 @@ import * as gitRefs from '../git-refs';
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'git-tags';
export const registryUrlRestriction = 'disallowed';
export const customRegistrySupport = false;

export async function getReleases({
lookupName,
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/github-releases/index.ts
Expand Up @@ -4,6 +4,7 @@ import { ensureTrailingSlash } from '../../util/url';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'github-releases';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://github.com'];
export const registryStrategy = 'first';

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/github-tags/index.ts
Expand Up @@ -6,6 +6,7 @@ import * as githubReleases from '../github-releases';
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'github-tags';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://github.com'];
export const registryStrategy = 'first';

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/gitlab-tags/index.ts
Expand Up @@ -6,6 +6,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';
const gitlabApi = new GitlabHttp();

export const id = 'gitlab-tags';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://gitlab.com'];
export const registryStrategy = 'first';

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/go/index.ts
Expand Up @@ -11,7 +11,7 @@ import * as gitlab from '../gitlab-tags';
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'go';
export const registryUrlRestriction = 'disallowed';
export const customRegistrySupport = false;

const http = new Http(id);
const gitlabRegExp = /^(https:\/\/[^/]*gitlab.[^/]*)\/(.*)$/;
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/gradle-version/index.ts
Expand Up @@ -5,6 +5,7 @@ import * as gradleVersioning from '../../versioning/gradle';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'gradle-version';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://services.gradle.org/versions/all'];
export const defaultVersioning = gradleVersioning.id;
export const registryStrategy = 'merge';
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/helm/index.ts
Expand Up @@ -12,6 +12,7 @@ export const id = 'helm';

const http = new Http(id);

export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://charts.helm.sh/stable'];
export const registryStrategy = 'first';

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/hex/index.ts
Expand Up @@ -6,7 +6,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'hex';
export const defaultRegistryUrls = ['https://hex.pm/'];
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;
export const defaultVersioning = hexVersioning.id;

const http = new Http(id);
Expand Down
40 changes: 12 additions & 28 deletions lib/datasource/index.ts
Expand Up @@ -171,17 +171,17 @@ function resolveRegistryUrls(
datasource: DatasourceApi,
extractedUrls: string[]
): string[] {
const { defaultRegistryUrls = [], registryUrlRestriction } = datasource;
const customUrls = extractedUrls?.filter(Boolean);
if (registryUrlRestriction) {
if (is.nonEmptyArray(customUrls)) {
const { defaultRegistryUrls = [] } = datasource;
if (!datasource.customRegistrySupport) {
if (is.nonEmptyArray(extractedUrls)) {
logger.warn(
{ datasource: datasource.id, customUrls },
'Ignoring custom registryUrls as they cannot be overridden'
{ datasource: datasource.id, registryUrls: extractedUrls },
'Custom datasources are not allowed for this datasource and will be ignored'
);
}
return defaultRegistryUrls;
}
const customUrls = extractedUrls?.filter(Boolean);
let registryUrls: string[];
if (is.nonEmptyArray(customUrls)) {
registryUrls = [...customUrls];
Expand All @@ -207,34 +207,18 @@ async function fetchReleases(
const datasource = load(datasourceName);
const registryUrls = resolveRegistryUrls(datasource, config.registryUrls);
let dep: ReleaseResult = null;
const registryStrategy = datasource.registryStrategy || 'hunt';
try {
if (
datasource.registryStrategy ||
datasource.registryUrlRestriction === 'fixed'
) {
// istanbul ignore if
if (!registryUrls.length) {
logger.warn(
{ datasource: datasourceName, depName: config.depName },
'Missing registryUrls for registryStrategy'
);
return null;
}
if (datasource.registryStrategy === 'first') {
if (is.nonEmptyArray(registryUrls)) {
if (registryStrategy === 'first') {
dep = await firstRegistry(config, datasource, registryUrls);
} else if (datasource.registryStrategy === 'hunt') {
} else if (registryStrategy === 'hunt') {
dep = await huntRegistries(config, datasource, registryUrls);
} else if (datasource.registryStrategy === 'merge') {
} else if (registryStrategy === 'merge') {
dep = await mergeRegistries(config, datasource, registryUrls);
} else {
// Default to hunting default registries if no rangeStrategy provided
dep = await huntRegistries(config, datasource, registryUrls);
}
} else {
dep = await datasource.getReleases({
...config,
registryUrls,
});
dep = await datasource.getReleases(config);
}
} catch (err) {
if (err.message === HOST_DISABLED || err.err?.message === HOST_DISABLED) {
Expand Down
2 changes: 2 additions & 0 deletions lib/datasource/jenkins-plugins/index.ts
@@ -1,3 +1,5 @@
export { id } from './common';
export { getReleases } from './get';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://updates.jenkins.io'];
export const registryStrategy = 'hunt';
1 change: 1 addition & 0 deletions lib/datasource/maven/index.ts
Expand Up @@ -13,6 +13,7 @@ import { downloadHttpProtocol, isHttpResourceExists } from './util';

export { id } from './common';

export const customRegistrySupport = true;
export const defaultRegistryUrls = [MAVEN_REPO];
export const defaultVersioning = mavenVersioning.id;
export const registryStrategy = 'merge';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/npm/index.ts
Expand Up @@ -5,4 +5,4 @@ export { getReleases } from './releases';
export { getNpmrc, setNpmrc } from './npmrc';
export { id } from './common';
export const defaultVersioning = npmVersioning.id;
export const registryUrlRestriction = 'disallowed';
export const customRegistrySupport = false;
1 change: 1 addition & 0 deletions lib/datasource/nuget/index.ts
Expand Up @@ -7,6 +7,7 @@ import * as v3 from './v3';

export { id } from './common';

export const customRegistrySupport = true;
export const defaultRegistryUrls = [v3.getDefaultFeed()];
export const defaultVersioning = nugetVersioning.id;
export const registryStrategy = 'merge';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/orb/index.ts
Expand Up @@ -5,7 +5,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'orb';
export const defaultRegistryUrls = ['https://circleci.com/'];
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;

const http = new Http(id);

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/packagist/index.ts
Expand Up @@ -11,6 +11,7 @@ import * as composerVersioning from '../../versioning/composer';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'packagist';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://packagist.org'];
export const defaultVersioning = composerVersioning.id;
export const registryStrategy = 'hunt';
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/pod/index.ts
Expand Up @@ -9,6 +9,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'pod';

export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://cdn.cocoapods.org'];
export const registryStrategy = 'hunt';

Expand Down
1 change: 1 addition & 0 deletions lib/datasource/pypi/index.ts
Expand Up @@ -8,6 +8,7 @@ import * as pep440 from '../../versioning/pep440';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';

export const id = 'pypi';
export const customRegistrySupport = true;
export const defaultRegistryUrls = [
process.env.PIP_INDEX_URL || 'https://pypi.org/pypi/',
];
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/repology/index.ts
Expand Up @@ -7,6 +7,7 @@ import { getQueryString } from '../../util/url';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'repology';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://repology.org/'];
export const registryStrategy = 'hunt';

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/ruby-version/index.ts
Expand Up @@ -7,7 +7,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'ruby-version';
export const defaultRegistryUrls = ['https://www.ruby-lang.org/'];
export const registryUrlRestriction = 'fixed';
export const customRegistrySupport = false;
export const defaultVersioning = rubyVersioningId;

const http = new Http(id);
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/rubygems/index.ts
Expand Up @@ -2,6 +2,7 @@ import * as rubyVersioning from '../../versioning/ruby';

export { getReleases } from './releases';
export { id } from './common';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://rubygems.org'];
export const defaultVersioning = rubyVersioning.id;
export const registryStrategy = 'hunt';
1 change: 1 addition & 0 deletions lib/datasource/sbt-package/index.ts
Expand Up @@ -8,6 +8,7 @@ import { parseIndexDir } from '../sbt-plugin/util';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'sbt-package';
export const customRegistrySupport = true;
export const defaultRegistryUrls = [MAVEN_REPO];
export const defaultVersioning = ivyVersioning.id;
export const registryStrategy = 'hunt';
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/sbt-plugin/index.ts
Expand Up @@ -12,6 +12,7 @@ import type { GetReleasesConfig, ReleaseResult } from '../types';
import { SBT_PLUGINS_REPO, parseIndexDir } from './util';

export const id = 'sbt-plugin';
export const customRegistrySupport = true;
export const defaultRegistryUrls = [SBT_PLUGINS_REPO];
export const defaultVersioning = ivyVersioning.id;
export const registryStrategy = 'hunt';
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/terraform-module/index.ts
Expand Up @@ -6,6 +6,7 @@ import * as hashicorpVersioning from '../../versioning/hashicorp';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'terraform-module';
export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://registry.terraform.io'];
export const defaultVersioning = hashicorpVersioning.id;
export const registryStrategy = 'first';
Expand Down
1 change: 1 addition & 0 deletions lib/datasource/terraform-provider/index.ts
Expand Up @@ -7,6 +7,7 @@ import { getTerraformServiceDiscoveryResult } from '../terraform-module';
import type { GetReleasesConfig, ReleaseResult } from '../types';

export const id = 'terraform-provider';
export const customRegistrySupport = true;
export const defaultRegistryUrls = [
'https://registry.terraform.io',
'https://releases.hashicorp.com',
Expand Down
6 changes: 2 additions & 4 deletions lib/datasource/types.ts
Expand Up @@ -73,11 +73,9 @@ export interface DatasourceApi {
registryStrategy?: 'first' | 'hunt' | 'merge';

/**
* Whether restrictions apply on custom registryUrls. If unspecified, it means custom registryUrls are allowed (no retriction).
* fixed: the default registryUrl settings can't be overridden
* disallowed: registryUrls are not applicable to this datasource
* Whether custom registryUrls are allowed.
*/
registryUrlRestriction?: 'fixed' | 'disallowed';
customRegistrySupport: boolean;

/**
* Whether to perform caching in the datasource index/wrapper or not.
Expand Down

0 comments on commit f1a4102

Please sign in to comment.