From eb87cbbfa5d6f2efa5fb4e9562f64871e71d7b54 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 24 Apr 2024 10:01:37 -0400 Subject: [PATCH] feat(manager/gitlabci): support registry aliases (#28607) Co-authored-by: Sebastian Poxhofer --- lib/modules/manager/gitlabci/extract.spec.ts | 63 ++++++++++++++++++++ lib/modules/manager/gitlabci/extract.ts | 10 +++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lib/modules/manager/gitlabci/extract.spec.ts b/lib/modules/manager/gitlabci/extract.spec.ts index c66bdc621edfb1..84ab81e28c5b9f 100644 --- a/lib/modules/manager/gitlabci/extract.spec.ts +++ b/lib/modules/manager/gitlabci/extract.spec.ts @@ -354,6 +354,69 @@ describe('modules/manager/gitlabci/extract', () => { expect(extractFromJob({ image: 'image:test' })).toEqual(expectedRes); }); + it('extracts component references via registry aliases', () => { + const registryAliases = { + $CI_SERVER_HOST: 'gitlab.example.com', + }; + const content = codeBlock` + include: + - component: $CI_SERVER_HOST/an-org/a-project/a-component@1.0 + inputs: + stage: build + - component: $CI_SERVER_HOST/an-org/a-subgroup/a-project/a-component@e3262fdd0914fa823210cdb79a8c421e2cef79d8 + - component: $CI_SERVER_HOST/an-org/a-subgroup/another-project/a-component@main + - component: $CI_SERVER_HOST/another-org/a-project/a-component@~latest + inputs: + stage: test + - component: $CI_SERVER_HOST/malformed-component-reference + - component: + 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 + `; + const res = extractPackageFile(content, '', { + registryAliases, + }); + expect(res?.deps).toMatchObject([ + { + currentValue: '1.0', + datasource: 'gitlab-tags', + depName: 'an-org/a-project', + depType: 'repository', + registryUrls: ['https://gitlab.example.com'], + }, + { + currentValue: 'e3262fdd0914fa823210cdb79a8c421e2cef79d8', + datasource: 'gitlab-tags', + depName: 'an-org/a-subgroup/a-project', + depType: 'repository', + registryUrls: ['https://gitlab.example.com'], + }, + { + currentValue: 'main', + datasource: 'gitlab-tags', + depName: 'an-org/a-subgroup/another-project', + depType: 'repository', + registryUrls: ['https://gitlab.example.com'], + }, + { + currentValue: '~latest', + datasource: 'gitlab-tags', + depName: 'another-org/a-project', + depType: 'repository', + registryUrls: ['https://gitlab.example.com'], + skipReason: 'unsupported-version', + }, + { + currentValue: '1.0', + datasource: 'gitlab-tags', + depName: 'an-org/a-project', + depType: 'repository', + registryUrls: ['https://other-gitlab.example.com'], + }, + ]); + }); + it('extracts component references', () => { const content = codeBlock` include: diff --git a/lib/modules/manager/gitlabci/extract.ts b/lib/modules/manager/gitlabci/extract.ts index d04a85daf220ac..4a0e1872d76be2 100644 --- a/lib/modules/manager/gitlabci/extract.ts +++ b/lib/modules/manager/gitlabci/extract.ts @@ -120,6 +120,7 @@ function getAllIncludeComponents( function extractDepFromIncludeComponent( includeComponent: GitlabIncludeComponent, + registryAliases?: Record, ): PackageDependency | null { const componentReference = componentReferenceRegex.exec( includeComponent.component, @@ -139,6 +140,10 @@ function extractDepFromIncludeComponent( ); return null; } + const aliasValue = registryAliases?.[componentReference.fqdn]; + if (aliasValue) { + componentReference.fqdn = aliasValue; + } const dep: PackageDependency = { datasource: GitlabTagsDatasource.id, @@ -209,7 +214,10 @@ export function extractPackageFile( const includedComponents = getAllIncludeComponents(doc); for (const includedComponent of includedComponents) { - const dep = extractDepFromIncludeComponent(includedComponent); + const dep = extractDepFromIncludeComponent( + includedComponent, + config.registryAliases, + ); if (dep) { deps.push(dep); }