mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 23:11:31 +00:00
feat(manager/gitlabci): support registry aliases (#28607)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -120,6 +120,7 @@ function getAllIncludeComponents(
|
||||
|
||||
function extractDepFromIncludeComponent(
|
||||
includeComponent: GitlabIncludeComponent,
|
||||
registryAliases?: Record<string, string>,
|
||||
): 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user