mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 15:01:49 +00:00
59852479bf
* test(versioning): cover four uncovered guards - `cargo`: a converted range whose operators are already attached to their versions, so `npm2cargo` leaves the elements alone - `hashicorp`: a widen on a complex range ending in `>=`, which the underlying semver implementation refuses and returns null for - `poetry`: a version list holding an unparseable entry, for both `getSatisfyingVersion` and `minSatisfyingVersion`, plus the same widen refusal, which falls back to the current value - `swift`: an open-ended range whose bound is not a valid semver Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop two guards that cannot be false - `hermit`: `major` is the only mandatory group in the version regex, so the `if (major)` around the first release segment always holds; the sibling parser already pushes it unconditionally - `rpm`: after `c1 === c2` is ruled out, one of `c1 > c2` and `c1 < c2` must hold, so the second comparison becomes a ternary Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/gradle): cover three uncovered guards - `getMajor` on a version whose leading token is not a number - `getSatisfyingVersion` with a later match that is not greater than the one already held - `minSatisfyingVersion` with a later match that is not smaller than the one already held Two branches in `compare.ts` are still open and are looked at next. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/ivy): cover a later match that is not the greatest `getSatisfyingVersion` kept every matching version it walked past, so the guard that holds on to the one already found was never taken. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop three guards that cannot be false - `gradle`: `tokenCmp` compares two tokens whose only types are `Number` and `String`, so once both-numbers and both-strings are handled exactly one side is a number; the chain becomes a ternary and the unreachable `return 0` goes - `ivy`: `tokenize` always yields at least one token for a non-empty version, so the length check around the last one always holds - `ivy`: `rangeToStr` only returns null for a null range, which the `length === 1` check above it already rules out Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/nuget): cover a later match that is not the greatest Both loops in `getSatisfyingVersion` walked version lists that only ever climbed, so the guard that holds on to the candidate already found was never taken -- once for a bracket range, once for a bare version acting as a minimum. Also pin down that a floating range needs a major component: `-*` alone does not parse. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop three more guards that cannot be false - `maven`: the interval picked for auto-extension is only picked when the new value is at or past its upper bound, and that upper bound is the lower one incremented, so the new value never sorts below the lower bound - `maven`: an interval never has both bounds open, because the parser only nulls one side when the other is a version - `nuget`: a floating range always carries a major component, so neither the parser's NaN check nor the serializer's undefined check can fail Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning/pep440): drop three unreachable range paths `updateRangeValue` handles `!=`, a `.*` prefix, `~=`, `==` and `<=` itself, `handleUpperBound` handles `<`, and `parseCurrentRange` rejects `===`. Only `>` and `>=` can reach `handleLowerBound`, so its operator check always holds and it never returns null. Making it total removes the null check at the call site as well. This does drop the `logger.error` that followed, which was guarded by a comment saying it could not happen unless pep440 itself changed. `isLessThanRange` classifies the same fixed operator set, so the last check there is the only one left and its fallback was dead. `divideCompatibleReleaseRange` only ever sees a `~=` version, and pep440 requires at least two release components after that operator, so there is always a component to drop. A new test pins down that `~=7` is not a valid range. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning): cover three more uncovered guards - `elm`: a widen where the new version sits below the lower bound, so the upper bound is kept rather than extended - `hex`: a widen on a complex range ending in `>=`, which the underlying semver implementation refuses and returns null for - `rust-release-channel`: a concrete current version paired with a channel name as the new version, which falls through to the new version unchanged Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop two more guards that cannot be false - `composer`: `getNewValue` falls back to the new version whenever nothing else matched, so it never returns null and the recursive call in the or-range path always has a value to work with - `docker`: a version's prerelease is always a string, so once an empty one on either side is handled, the remaining pair is both non-empty and unequal Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(config,datasource): cover two more uncovered guards - `config/validation`: `hostRules[].allowInternal` nested inside a `packageRules[]` entry, which reports a plain configuration error rather than a security one, because nested host rules are never applied - `datasource/docker`: a non-list manifest whose response carries no `docker-content-digest` header, so the digest falls back to the hash of the manifest body Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(config,datasource): unwind three branches v8 could not count - `config/decrypt` and `datasource/docker/common` each picked a response with an `await` inside a ternary. v8 gives the branch that follows such a ternary a negative hit count, which the reporters read as uncovered even though both paths run. Spelling the choice as an if/else makes the count come out right; behaviour is unchanged. - `datasource/index` and `datasource/npm/npmrc` each ended an exhaustive chain with an `else if` whose implicit else v8 counts but nothing can reach: `registryStrategy` is one of three literals, and `npmrc` starts as an object and is only ever reassigned to one. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(workers/global): cover seven uncovered guards The config parsers rewrite legacy boolean spellings of `dryRun`, `requireConfig` and `platformCommit`, but nothing passed a value that was already current, so the fall-through of each chain went untaken. Cover it from both the CLI and the environment. Also cover a datasource env var that names no auth field, one whose value is undefined, a default config file that cannot be read, and the error `isLimitReached` throws when asked for a concurrent limit without a branch config. That last one had an ignore hint saying it should not happen; the error message documents the contract, so it is now tested and the hint is gone. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(workers/global): drop a guard that cannot be false `getConfig` in the additional-config-file parser returns early unless `RENOVATE_ADDITIONAL_CONFIG_FILE` is set, so by the time a parse error is being classified the variable is always present. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(workers/repository): drop a dead changelog file lookup The gitea, gitlab and forgejo changelog sources each declared `files` as an empty array and then guarded the only assignment to it with `if (!files.length)`, which is always true one line after the declaration. Collapse it to the filter itself. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * ci: ratchet the branch coverage threshold A full run on this branch reports 100% statements (49471/49471), 100% functions (7381/7381), 100% lines (48961/48961) and 99.73% branches (25690/25759), up from 99.53% before this branch's work. The threshold moves to 99.71, keeping the same rounding-down margin as before. Statements, functions and lines are already pinned at 100 and stay there. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(config,datasource): say why the ternary was unwound Both sites now carry a comment explaining that the if/else is deliberate: v8 gives the branch following an `await` inside a ternary a negative hit count, which the coverage reporters read as uncovered. `apiCheckResponse` also gets an explicit `HttpResponse<unknown>` type, which is what the two branches have in common and what `isECRMaxResultsResponse` already expects. Also fix a type error in the new config file spec: the `pathExists` spy needs the same `as never` cast the surrounding tests use. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning/pep440): use a template literal in handleLowerBound The exclude-style return is the one line this branch rewrote in that function, so it now builds its string with a template literal instead of the `+` operator. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(workers/global): drop the cast from the limits throw test Calling the overload with a non-null assertion on the config argument says the same thing without retyping the whole function. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> --------- Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>
408 lines
14 KiB
TypeScript
408 lines
14 KiB
TypeScript
import { isNonEmptyString, isString, isUndefined } from '@sindresorhus/is';
|
|
import {
|
|
HOST_BLOCKED,
|
|
HOST_DISABLED,
|
|
PAGE_NOT_FOUND_ERROR,
|
|
} from '../../../constants/error-messages.ts';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { ExternalHostError } from '../../../types/errors/external-host-error.ts';
|
|
import { coerceArray } from '../../../util/array.ts';
|
|
import { detectPlatform } from '../../../util/common.ts';
|
|
import { parseGitUrl } from '../../../util/git/url.ts';
|
|
import { toSha256 } from '../../../util/hash.ts';
|
|
import * as hostRules from '../../../util/host-rules.ts';
|
|
import { memCacheProvider } from '../../../util/http/cache/memory-http-cache-provider.ts';
|
|
import type { Http } from '../../../util/http/index.ts';
|
|
import type {
|
|
HttpOptions,
|
|
HttpResponse,
|
|
OutgoingHttpHeaders,
|
|
} from '../../../util/http/types.ts';
|
|
import { refusedHostMessage } from '../../../util/http/util.ts';
|
|
import type { ParamsChallenge } from '../../../util/http/www-authenticate.ts';
|
|
import { BearerScheme, parse } from '../../../util/http/www-authenticate.ts';
|
|
import { coerceObject } from '../../../util/object.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import { addSecretForSanitizing } from '../../../util/sanitize.ts';
|
|
import {
|
|
ensureTrailingSlash,
|
|
parseUrl,
|
|
trimTrailingSlash,
|
|
} from '../../../util/url.ts';
|
|
import { api as dockerVersioning } from '../../versioning/docker/index.ts';
|
|
import { getGoogleAuthToken } from '../util.ts';
|
|
import { ecrRegex, getECRAuthToken, isECRMaxResultsResponse } from './ecr.ts';
|
|
import { googleRegex } from './google.ts';
|
|
import type { OciHelmConfig } from './schema.ts';
|
|
import { RegistryAuthToken } from './schema.ts';
|
|
import type { RegistryRepository } from './types.ts';
|
|
|
|
export const dockerDatasourceId = 'docker';
|
|
|
|
export const imageUrlLabel = 'org.opencontainers.image.url';
|
|
|
|
export const sourceLabel = 'org.opencontainers.image.source';
|
|
export const sourceLabels = [sourceLabel, 'org.label-schema.vcs-url'] as const;
|
|
|
|
export const gitRefLabel = 'org.opencontainers.image.revision';
|
|
|
|
export const DOCKER_HUB = 'https://index.docker.io';
|
|
|
|
export function isDockerHost(host: string): boolean {
|
|
const regex = regEx(/(?:^|\.)docker\.io$/);
|
|
return regex.test(host);
|
|
}
|
|
|
|
export async function getAuthHeaders(
|
|
http: Http,
|
|
registryHost: string,
|
|
dockerRepository: string,
|
|
apiCheckUrl = `${registryHost}/v2/`,
|
|
): Promise<OutgoingHttpHeaders | undefined> {
|
|
try {
|
|
const options = {
|
|
throwHttpErrors: false,
|
|
noAuth: true,
|
|
cacheProvider: memCacheProvider,
|
|
};
|
|
// Written as an if/else rather than a ternary on purpose: v8 gives the
|
|
// branch that follows an `await` inside a ternary a negative hit count,
|
|
// which the coverage reporters then read as uncovered.
|
|
let apiCheckResponse: HttpResponse<unknown>;
|
|
if (apiCheckUrl.endsWith('/v2/')) {
|
|
apiCheckResponse = await http.get(apiCheckUrl, options);
|
|
} else {
|
|
// use json request, as this will be cached for tags, so it returns json
|
|
// TODO: add cache test
|
|
apiCheckResponse = await http.getJsonUnchecked(apiCheckUrl, options);
|
|
}
|
|
|
|
if (apiCheckResponse.statusCode === 200) {
|
|
logger.debug(`No registry auth required for ${apiCheckUrl}`);
|
|
return {};
|
|
}
|
|
if (apiCheckResponse.statusCode === 404) {
|
|
logger.debug(`Page Not Found ${apiCheckUrl}`);
|
|
// throw error up to be caught and potentially retried with library/ prefix
|
|
throw new Error(PAGE_NOT_FOUND_ERROR);
|
|
}
|
|
// Some ECR-compatible private registries (e.g. corporate Docker proxies) reject
|
|
// n>1000 with 405 even on the auth-probe request. Fall back to probing the base
|
|
// /v2/ endpoint so getAuthHeaders can still obtain a valid token; the main fetch
|
|
// loop already retries with n=1000 when it encounters this same error.
|
|
if (isECRMaxResultsResponse(apiCheckResponse)) {
|
|
logger.debug(
|
|
{ apiCheckUrl },
|
|
'Registry rejected n>1000 on auth probe; retrying auth check via base /v2/ endpoint',
|
|
);
|
|
return getAuthHeaders(http, registryHost, dockerRepository);
|
|
}
|
|
if (
|
|
apiCheckResponse.statusCode !== 401 ||
|
|
!isNonEmptyString(apiCheckResponse.headers['www-authenticate'])
|
|
) {
|
|
logger.warn(
|
|
{ apiCheckUrl, res: apiCheckResponse },
|
|
'Invalid registry response',
|
|
);
|
|
return undefined;
|
|
}
|
|
|
|
const rule = hostRules.find({
|
|
hostType: dockerDatasourceId,
|
|
url: apiCheckUrl,
|
|
});
|
|
const opts: HttpOptions = {};
|
|
|
|
if (ecrRegex.test(registryHost)) {
|
|
logger.once.debug(`hostRules: ecr auth for ${registryHost}`);
|
|
logger.trace(
|
|
{ registryHost, dockerRepository },
|
|
`Using ecr auth for Docker registry`,
|
|
);
|
|
const [, region] = coerceArray(ecrRegex.exec(registryHost));
|
|
const auth = await getECRAuthToken(region, rule);
|
|
if (auth) {
|
|
opts.headers = { authorization: `Basic ${auth}` };
|
|
}
|
|
} else if (
|
|
googleRegex.test(registryHost) &&
|
|
isUndefined(rule.username) &&
|
|
isUndefined(rule.password) &&
|
|
isUndefined(rule.token)
|
|
) {
|
|
logger.once.debug(`hostRules: google auth for ${registryHost}`);
|
|
logger.trace(
|
|
{ registryHost, dockerRepository },
|
|
`Using google auth for Docker registry`,
|
|
);
|
|
const auth = await getGoogleAuthToken();
|
|
if (auth) {
|
|
opts.headers = { authorization: `Basic ${auth}` };
|
|
} else {
|
|
logger.once.debug(
|
|
{ registryHost, dockerRepository },
|
|
'Could not get Google access token, using no auth',
|
|
);
|
|
}
|
|
} else if (rule.username && rule.password) {
|
|
logger.once.debug(`hostRules: basic auth for ${registryHost}`);
|
|
logger.trace(
|
|
{ registryHost, dockerRepository },
|
|
`Using basic auth for Docker registry`,
|
|
);
|
|
const auth = Buffer.from(`${rule.username}:${rule.password}`).toString(
|
|
'base64',
|
|
);
|
|
opts.headers = { authorization: `Basic ${auth}` };
|
|
} else if (rule.token) {
|
|
const authType = rule.authType ?? 'Bearer';
|
|
logger.once.debug(
|
|
`hostRules: ${authType} token auth for ${registryHost}`,
|
|
);
|
|
logger.trace(
|
|
{ registryHost, dockerRepository },
|
|
`Using ${authType} token for Docker registry`,
|
|
);
|
|
opts.headers = { authorization: `${authType} ${rule.token}` };
|
|
}
|
|
|
|
const challenges = parse(apiCheckResponse.headers['www-authenticate']);
|
|
const authenticateHeader = challenges.find(
|
|
(c): c is ParamsChallenge => c.scheme === BearerScheme,
|
|
);
|
|
|
|
// If realm isn't an url, we should directly use auth header
|
|
// Can happen when we get a Basic auth or some other auth type
|
|
// * WWW-Authenticate: Basic realm="Artifactory Realm"
|
|
// * Www-Authenticate: Basic realm="https://123456789.dkr.ecr.eu-central-1.amazonaws.com/",service="ecr.amazonaws.com"
|
|
// * www-authenticate: Bearer realm="https://ghcr.io/token",service="ghcr.io",scope="repository:user/image:pull"
|
|
// * www-authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"
|
|
// * www-authenticate: Bearer realm="https://codeberg.org/v2/token",service="container_registry",scope="*",Basic realm="https://codeberg.org/v2",service="container_registry",scope="*"
|
|
if (
|
|
!authenticateHeader ||
|
|
!isString(authenticateHeader.params?.realm) ||
|
|
parseUrl(authenticateHeader.params.realm) === null
|
|
) {
|
|
logger.once.debug(`hostRules: testing direct auth for ${registryHost}`);
|
|
logger.trace(
|
|
{ registryHost, dockerRepository, authenticateHeader },
|
|
`Invalid realm, testing direct auth`,
|
|
);
|
|
return opts.headers ?? undefined;
|
|
}
|
|
|
|
// already guarded by above clause
|
|
const authUrl = parseUrl(`${authenticateHeader.params.realm}`)!;
|
|
|
|
// repo isn't known to server yet, so causing wrong scope `repository:user/image:pull`
|
|
if (
|
|
isString(authenticateHeader.params.scope) &&
|
|
!apiCheckUrl.endsWith('/v2/')
|
|
) {
|
|
authUrl.searchParams.append('scope', authenticateHeader.params.scope);
|
|
} else {
|
|
authUrl.searchParams.append(
|
|
'scope',
|
|
`repository:${dockerRepository}:pull`,
|
|
);
|
|
}
|
|
|
|
if (isString(authenticateHeader.params.service)) {
|
|
authUrl.searchParams.append('service', authenticateHeader.params.service);
|
|
}
|
|
|
|
logger.trace(
|
|
{ registryHost, dockerRepository, authUrl: authUrl.href },
|
|
`Obtaining docker registry token`,
|
|
);
|
|
opts.noAuth = true;
|
|
opts.cacheProvider = memCacheProvider;
|
|
const authResponse = (
|
|
await http.getJson(authUrl.href, opts, RegistryAuthToken)
|
|
).body;
|
|
|
|
const token = authResponse.token ?? authResponse.access_token;
|
|
/* v8 ignore next -- TODO: add test */
|
|
if (!token) {
|
|
logger.warn('Failed to obtain docker registry token');
|
|
return undefined;
|
|
}
|
|
// sanitize token
|
|
addSecretForSanitizing(token);
|
|
return {
|
|
authorization: `Bearer ${token}`,
|
|
};
|
|
} catch (err) /* istanbul ignore next */ {
|
|
/* v8 ignore if -- quay.io errors are swallowed pending #9604, not reproduced in specs */
|
|
if (err.host === 'quay.io') {
|
|
// TODO: debug why quay throws errors (#9604)
|
|
return undefined;
|
|
}
|
|
/* v8 ignore if -- registry auth rejection is logged and swallowed, not mocked in specs */
|
|
if (err.statusCode === 401) {
|
|
logger.debug(
|
|
{ registryHost, dockerRepository },
|
|
'Unauthorized docker lookup',
|
|
);
|
|
logger.debug({ err });
|
|
return undefined;
|
|
}
|
|
/* v8 ignore if -- registry permission rejection is logged and swallowed, not mocked in specs */
|
|
if (err.statusCode === 403) {
|
|
logger.debug(
|
|
{ registryHost, dockerRepository },
|
|
'Not allowed to access docker registry',
|
|
);
|
|
logger.debug({ err });
|
|
return undefined;
|
|
}
|
|
if (err.name === 'RequestError' && isDockerHost(registryHost)) {
|
|
throw new ExternalHostError(err);
|
|
}
|
|
/* v8 ignore if -- Docker Hub rate limiting maps to ExternalHostError, not mocked in specs */
|
|
if (err.statusCode === 429 && isDockerHost(registryHost)) {
|
|
throw new ExternalHostError(err);
|
|
}
|
|
/* v8 ignore if -- registry server errors map to ExternalHostError, not mocked in specs */
|
|
if (err.statusCode >= 500 && err.statusCode < 600) {
|
|
throw new ExternalHostError(err);
|
|
}
|
|
if (err.message === PAGE_NOT_FOUND_ERROR) {
|
|
throw err;
|
|
}
|
|
/* v8 ignore if -- hostRules-disabled host is swallowed silently, not mocked in specs */
|
|
if ([HOST_BLOCKED, HOST_DISABLED].includes(err.message)) {
|
|
logger.trace(
|
|
{ registryHost, dockerRepository, err },
|
|
refusedHostMessage(err),
|
|
);
|
|
return undefined;
|
|
}
|
|
logger.warn(
|
|
{ registryHost, dockerRepository, err },
|
|
'Error obtaining docker token',
|
|
);
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function getRegistryRepository(
|
|
packageName: string,
|
|
registryUrl: string,
|
|
): RegistryRepository {
|
|
if (registryUrl !== DOCKER_HUB) {
|
|
const registryEndingWithSlash = ensureTrailingSlash(
|
|
registryUrl.replace(regEx(/^https?:\/\//), ''),
|
|
);
|
|
if (packageName.startsWith(registryEndingWithSlash)) {
|
|
let registryHost = trimTrailingSlash(registryUrl);
|
|
if (!regEx(/^https?:\/\//).test(registryHost)) {
|
|
registryHost = `https://${registryHost}`;
|
|
}
|
|
let dockerRepository = packageName.replace(registryEndingWithSlash, '');
|
|
const fullUrl = `${registryHost}/${dockerRepository}`;
|
|
const parsedFullUrl = parseUrl(fullUrl);
|
|
if (!parsedFullUrl) {
|
|
return { registryHost, dockerRepository };
|
|
}
|
|
registryHost = parsedFullUrl.origin;
|
|
dockerRepository = parsedFullUrl.pathname.substring(1);
|
|
return {
|
|
registryHost,
|
|
dockerRepository,
|
|
};
|
|
}
|
|
}
|
|
let registryHost = registryUrl;
|
|
const split = packageName.split('/');
|
|
if (split.length > 1 && (split[0].includes('.') || split[0].includes(':'))) {
|
|
[registryHost] = split;
|
|
split.shift();
|
|
}
|
|
let dockerRepository = split.join('/');
|
|
|
|
if (!regEx(/^https?:\/\//).test(registryHost)) {
|
|
registryHost = `https://${registryHost}`;
|
|
}
|
|
|
|
const { path, base } = coerceObject(
|
|
regEx(/^(?<base>https:\/\/[^/]+)\/(?<path>.+)$/).exec(registryHost)?.groups,
|
|
);
|
|
if (base && path) {
|
|
registryHost = base;
|
|
dockerRepository = `${trimTrailingSlash(path)}/${dockerRepository}`;
|
|
}
|
|
|
|
registryHost = registryHost
|
|
.replace('https://docker.io', 'https://index.docker.io')
|
|
.replace('https://registry-1.docker.io', 'https://index.docker.io');
|
|
|
|
const opts = hostRules.find({
|
|
hostType: dockerDatasourceId,
|
|
url: registryHost,
|
|
});
|
|
if (opts?.insecureRegistry) {
|
|
registryHost = registryHost.replace('https', 'http');
|
|
}
|
|
if (registryHost.endsWith('.docker.io') && !dockerRepository.includes('/')) {
|
|
dockerRepository = `library/${dockerRepository}`;
|
|
}
|
|
return {
|
|
registryHost,
|
|
dockerRepository,
|
|
};
|
|
}
|
|
|
|
export function extractDigestFromResponseBody(
|
|
manifestResponse: HttpResponse,
|
|
): string {
|
|
return `sha256:${toSha256(manifestResponse.body)}`;
|
|
}
|
|
|
|
export function findLatestStable(tags: string[]): string | null {
|
|
let stable: string | null = null;
|
|
|
|
for (const tag of tags) {
|
|
if (!dockerVersioning.isValid(tag) || !dockerVersioning.isStable(tag)) {
|
|
continue;
|
|
}
|
|
|
|
if (!stable || dockerVersioning.isGreaterThan(tag, stable)) {
|
|
stable = tag;
|
|
}
|
|
}
|
|
|
|
return stable;
|
|
}
|
|
|
|
const chartRepo = regEx(/charts?|helm|helm-charts?/i);
|
|
|
|
function isPossibleChartRepo(url: string): boolean {
|
|
if (detectPlatform(url) === null) {
|
|
return false;
|
|
}
|
|
|
|
const parsed = parseGitUrl(url);
|
|
return chartRepo.test(parsed.name);
|
|
}
|
|
|
|
export function findHelmSourceUrl(release: OciHelmConfig): string | null {
|
|
if (release.home && isPossibleChartRepo(release.home)) {
|
|
return release.home;
|
|
}
|
|
|
|
if (!release.sources?.length) {
|
|
return null;
|
|
}
|
|
|
|
for (const url of release.sources) {
|
|
if (isPossibleChartRepo(url)) {
|
|
return url;
|
|
}
|
|
}
|
|
|
|
// fallback
|
|
return release.sources[0];
|
|
}
|