Files
renovate/lib/modules/manager/util.ts
T
Jamie Tanna 15d541461b refactor(manager): add utility for creating Artifact Error messages (#45218)
* refactor(manager); add utility for creating Artifact Error messages

To prevent ignoring linting rules for nullish coalescing, as well as for
future changes that will use this helper, we can extract out a helper
function for this.

Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io>
Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! refactor(manager); add utility for creating Artifact Error messages

---------

Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io>
2026-08-11 10:18:20 +00:00

69 lines
2.1 KiB
TypeScript

import { detectPlatform } from '../../util/common.ts';
import type { ExecError } from '../../util/exec/exec-error.ts';
import { parseGitUrl } from '../../util/git/url.ts';
import { GitRefsDatasource } from '../datasource/git-refs/index.ts';
import { GitTagsDatasource } from '../datasource/git-tags/index.ts';
import { GithubTagsDatasource } from '../datasource/github-tags/index.ts';
import { GitlabTagsDatasource } from '../datasource/gitlab-tags/index.ts';
import type { PackageDependency } from './types.ts';
export function applyGitSource(
dep: PackageDependency,
git: string,
rev: string | undefined,
tag: string | undefined,
branch: string | undefined,
): void {
if (tag) {
const platform = detectPlatform(git);
if (platform === 'github' || platform === 'gitlab') {
dep.datasource =
platform === 'github'
? GithubTagsDatasource.id
: GitlabTagsDatasource.id;
const { host, full_name } = parseGitUrl(git);
// Always use HTTPS for GitHub/GitLab API endpoints, even if the git URL protocol is SSH.
dep.registryUrls = [`https://${host}`];
dep.packageName = full_name;
} else {
dep.datasource = GitTagsDatasource.id;
dep.packageName = git;
}
dep.currentValue = tag;
dep.skipReason = undefined;
} else if (rev) {
dep.datasource = GitRefsDatasource.id;
dep.packageName = git;
dep.currentDigest = rev;
dep.replaceString = rev;
dep.skipReason = undefined;
} else {
dep.datasource = GitRefsDatasource.id;
dep.packageName = git;
dep.currentValue = branch;
dep.skipReason = branch ? 'git-dependency' : 'unspecified-version';
}
}
/**
* Given an {@link ExecError}, retrieve the message which will be used for an {@link ArtifactError}.
*
* An `ExecError` always carries a `stderr` property, so nullish coalescing would keep an empty string and render an artifact error with no message at all.
*
*/
export function artifactErrorMessageFromExecError(
err: Partial<ExecError>,
message: string,
): string {
if (err.stderr?.trim()) {
return err.stderr;
}
if (err.stdout?.trim()) {
return err.stdout;
}
return message;
}