renovate/lib/modules/manager/gitlabci/utils.ts
Rhys Arkins b6ed33ec01
fix(regex): don’t escape forward slash in fileMatch (#19314)
This cleanup of default `fileMatch` values should be backwards compatible.
2023-03-10 09:34:39 +01:00

40 lines
1.3 KiB
TypeScript

import { regEx } from '../../../util/regex';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency } from '../types';
const re = /!reference \[(.*?)\]/g;
/**
* Replaces GitLab reference tags before parsing, because our yaml parser cannot process them anyway.
* @param content pipeline yaml
* @returns replaced pipeline content
* https://docs.gitlab.com/ee/ci/yaml/#reference-tags
*/
export function replaceReferenceTags(content: string): string {
const res = content.replace(re, '');
return res;
}
const depProxyRe = regEx(
`(?<prefix>\\$\\{?CI_DEPENDENCY_PROXY_(?:DIRECT_)?GROUP_IMAGE_PREFIX\\}?/)(?<depName>.+)`
);
/**
* Get image dependencies respecting Gitlab Dependency Proxy
* @param imageName as used in .gitlab-ci.yml file
* @return package dependency for the image
*/
export function getGitlabDep(
imageName: string,
registryAliases?: Record<string, string>
): PackageDependency {
const match = depProxyRe.exec(imageName);
if (match?.groups) {
const dep = { ...getDep(match.groups.depName), replaceString: imageName };
// TODO: types (#7154)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
dep.autoReplaceStringTemplate = `${match.groups.prefix}${dep.autoReplaceStringTemplate}`;
return dep;
}
return getDep(imageName, true, registryAliases);
}