Skip to content

Commit

Permalink
refactor(manager/gitlabci): remove method "replaceReferenceTags"
Browse files Browse the repository at this point in the history
Since renovatebot#31336 the replacement of the reference tag from GitLab is not needed anymore
  • Loading branch information
websi committed Oct 4, 2024
1 parent 4d04357 commit 4e4d181
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
3 changes: 1 addition & 2 deletions lib/modules/manager/gitlabci-include/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
GitlabIncludeProject,
GitlabPipeline,
} from '../gitlabci/types';
import { replaceReferenceTags } from '../gitlabci/utils';
import type { PackageDependency, PackageFileContent } from '../types';

function extractDepFromIncludeFile(
Expand Down Expand Up @@ -76,7 +75,7 @@ export function extractPackageFile(
: null;
try {
// TODO: use schema (#9610)
const docs = parseYaml<GitlabPipeline>(replaceReferenceTags(content), {
const docs = parseYaml<GitlabPipeline>(content, {
uniqueKeys: false,
});
for (const doc of docs) {
Expand Down
15 changes: 11 additions & 4 deletions lib/modules/manager/gitlabci/common.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { codeBlock } from 'common-tags';
import { parseSingleYaml } from '../../../util/yaml';
import type { GitlabPipeline } from '../gitlabci/types';
import { replaceReferenceTags } from '../gitlabci/utils';
import {
filterIncludeFromGitlabPipeline,
isGitlabIncludeComponent,
Expand All @@ -12,7 +11,7 @@ import {

// TODO: use schema (#9610)
const pipeline = parseSingleYaml<GitlabPipeline>(
replaceReferenceTags(codeBlock`
codeBlock`
include:
- project: mikebryant/include-source-example
file: /template.yaml
Expand All @@ -25,7 +24,7 @@ const pipeline = parseSingleYaml<GitlabPipeline>(
script:
- !reference [.setup, script]
- !reference [arbitrary job name with space and no starting dot, nested1, nested2, nested3]`),
- !reference [arbitrary job name with space and no starting dot, nested1, nested2, nested3]`,
);
const includeLocal = { local: 'something' };
const includeProject = { project: 'something' };
Expand All @@ -37,7 +36,15 @@ describe('modules/manager/gitlabci/common', () => {
const filtered_pipeline = filterIncludeFromGitlabPipeline(pipeline);
expect(filtered_pipeline).not.toHaveProperty('include');
expect(filtered_pipeline).toEqual({
script: [null, null],
script: [
['.setup', 'script'],
[
'arbitrary job name with space and no starting dot',
'nested1',
'nested2',
'nested3',
],
],
});
});
});
Expand Down
11 changes: 1 addition & 10 deletions lib/modules/manager/gitlabci/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import type { PackageDependency } from '../types';
import { getGitlabDep, replaceReferenceTags } from './utils';
import { getGitlabDep } from './utils';

describe('modules/manager/gitlabci/utils', () => {
describe('getGitlabDep', () => {
Expand Down Expand Up @@ -82,12 +81,4 @@ describe('modules/manager/gitlabci/utils', () => {
});
});
});

describe('replaceReferenceTags', () => {
it('replaces all !reference tags with empty strings', () => {
const yamlFileReferenceConfig = Fixtures.get('gitlab-ci.reference.yaml');
const replaced = replaceReferenceTags(yamlFileReferenceConfig);
expect(replaced).not.toContain('!reference');
});
});
});
13 changes: 0 additions & 13 deletions lib/modules/manager/gitlabci/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@ 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>.+)`,
);
Expand Down

0 comments on commit 4e4d181

Please sign in to comment.