mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-26 07:20:39 +00:00
fix(manager/gitlabci): support alias with a path in component URL (#29707)
Co-authored-by: marco <marco@mybit.nl>
This commit is contained in:
@@ -37,5 +37,5 @@ export function isGitlabIncludeLocal(
|
||||
export function isGitlabIncludeComponent(
|
||||
include: GitlabInclude,
|
||||
): include is GitlabIncludeComponent {
|
||||
return !is.undefined((include as GitlabIncludeComponent).component);
|
||||
return is.string((include as GitlabIncludeComponent).component);
|
||||
}
|
||||
|
||||
@@ -231,6 +231,7 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
it('extract images via registry aliases', () => {
|
||||
const registryAliases = {
|
||||
$CI_REGISTRY: 'registry.com',
|
||||
$BUILD_IMAGES: 'registry.com/build-images',
|
||||
foo: 'foo.registry.com',
|
||||
};
|
||||
const res = extractPackageFile(
|
||||
@@ -242,6 +243,7 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
- foo/mariadb:10.4.11
|
||||
- name: $CI_REGISTRY/other/image1:1.0.0
|
||||
alias: imagealias1
|
||||
- $BUILD_IMAGES/image2:1.0.0
|
||||
`,
|
||||
'',
|
||||
{
|
||||
@@ -279,6 +281,16 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
depType: 'service-image',
|
||||
replaceString: '$CI_REGISTRY/other/image1:1.0.0',
|
||||
},
|
||||
{
|
||||
autoReplaceStringTemplate:
|
||||
'$BUILD_IMAGES/image2:{{#if newValue}}{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
|
||||
currentDigest: undefined,
|
||||
currentValue: '1.0.0',
|
||||
datasource: 'docker',
|
||||
depName: 'registry.com/build-images/image2',
|
||||
depType: 'service-image',
|
||||
replaceString: '$BUILD_IMAGES/image2:1.0.0',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -357,6 +369,7 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
it('extracts component references via registry aliases', () => {
|
||||
const registryAliases = {
|
||||
$CI_SERVER_HOST: 'gitlab.example.com',
|
||||
$COMPONENT_REGISTRY: 'gitlab.example.com/a-group',
|
||||
};
|
||||
const content = codeBlock`
|
||||
include:
|
||||
@@ -373,6 +386,7 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
malformed: true
|
||||
- component: $CI_SERVER_HOST/an-org/a-component@1.0
|
||||
- component: other-gitlab.example.com/an-org/a-project/a-component@1.0
|
||||
- component: $COMPONENT_REGISTRY/a-project/a-component@1.0
|
||||
`;
|
||||
const res = extractPackageFile(content, '', {
|
||||
registryAliases,
|
||||
@@ -414,6 +428,13 @@ describe('modules/manager/gitlabci/extract', () => {
|
||||
depType: 'repository',
|
||||
registryUrls: ['https://other-gitlab.example.com'],
|
||||
},
|
||||
{
|
||||
currentValue: '1.0',
|
||||
datasource: 'gitlab-tags',
|
||||
depName: 'a-group/a-project',
|
||||
depType: 'repository',
|
||||
registryUrls: ['https://gitlab.example.com'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -122,12 +122,16 @@ function extractDepFromIncludeComponent(
|
||||
includeComponent: GitlabIncludeComponent,
|
||||
registryAliases?: Record<string, string>,
|
||||
): PackageDependency | null {
|
||||
const componentReference = componentReferenceRegex.exec(
|
||||
includeComponent.component,
|
||||
)?.groups;
|
||||
let componentUrl = includeComponent.component;
|
||||
if (registryAliases) {
|
||||
for (const key in registryAliases) {
|
||||
componentUrl = componentUrl.replace(key, registryAliases[key]);
|
||||
}
|
||||
}
|
||||
const componentReference = componentReferenceRegex.exec(componentUrl)?.groups;
|
||||
if (!componentReference) {
|
||||
logger.debug(
|
||||
{ componentReference: includeComponent.component },
|
||||
{ componentReference: componentUrl },
|
||||
'Ignoring malformed component reference',
|
||||
);
|
||||
return null;
|
||||
@@ -135,15 +139,11 @@ function extractDepFromIncludeComponent(
|
||||
const projectPathParts = componentReference.projectPath.split('/');
|
||||
if (projectPathParts.length < 2) {
|
||||
logger.debug(
|
||||
{ componentReference: includeComponent.component },
|
||||
{ componentReference: componentUrl },
|
||||
'Ignoring component reference with incomplete project path',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
const aliasValue = registryAliases?.[componentReference.fqdn];
|
||||
if (aliasValue) {
|
||||
componentReference.fqdn = aliasValue;
|
||||
}
|
||||
|
||||
const dep: PackageDependency = {
|
||||
datasource: GitlabTagsDatasource.id,
|
||||
|
||||
Reference in New Issue
Block a user