mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
b62fe59594
We dropped the "bot" from our terminology long ago, but it looks like we've got some outdated docs + code that reference it. We should remove this to keep things consistent. A `fix`, as we're changing the commit author's name, and log lines. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import { getHttpUrl } from '../../../util/git/url.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import { GitTagsDatasource } from '../../datasource/git-tags/index.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../types.ts';
|
|
import { CopierAnswersFile } from './schema.ts';
|
|
|
|
const gitPrefixRegex = regEx(/^git\+/);
|
|
const httpProtocolRegex = regEx(/^https?:\/\//);
|
|
|
|
/**
|
|
* Copier supports `git+https://` and `git+ssh://` URL prefixes,
|
|
* but git itself does not understand them.
|
|
* Strip the `git+` prefix so the URL can be used with git directly.
|
|
*/
|
|
function stripGitPrefix(url: string): string {
|
|
return url.replace(gitPrefixRegex, '');
|
|
}
|
|
|
|
/**
|
|
* Convert SSH-style template URLs to their HTTPS equivalent for the
|
|
* datasource lookup, like the git-submodules manager does.
|
|
* This way the lookup can be authenticated via `hostRules` on accounts
|
|
* which access the Git host over HTTPS only.
|
|
* The answers file itself keeps the original URL.
|
|
*/
|
|
function getPackageName(srcPath: string): string {
|
|
const url = stripGitPrefix(srcPath);
|
|
if (httpProtocolRegex.test(url)) {
|
|
return url;
|
|
}
|
|
try {
|
|
return getHttpUrl(url);
|
|
} catch (err) {
|
|
logger.debug(
|
|
{ err, url },
|
|
'Failed to convert copier _src_path to an HTTP(S) URL',
|
|
);
|
|
return url;
|
|
}
|
|
}
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile?: string,
|
|
): PackageFileContent | null {
|
|
let parsed: CopierAnswersFile;
|
|
try {
|
|
parsed = CopierAnswersFile.parse(content);
|
|
} catch (err) {
|
|
logger.debug({ err, packageFile }, `Parsing Copier answers YAML failed`);
|
|
return null;
|
|
}
|
|
|
|
const deps: PackageDependency[] = [
|
|
{
|
|
datasource: GitTagsDatasource.id,
|
|
depName: parsed._src_path,
|
|
packageName: getPackageName(parsed._src_path),
|
|
depType: 'template',
|
|
currentValue: parsed._commit,
|
|
},
|
|
];
|
|
|
|
return {
|
|
deps,
|
|
};
|
|
}
|