-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
utils.ts
37 lines (33 loc) · 1.17 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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): PackageDependency {
const match = depProxyRe.exec(imageName);
if (match?.groups) {
const dep = { ...getDep(match.groups.depName), replaceString: imageName };
dep.autoReplaceStringTemplate =
match.groups.prefix + dep.autoReplaceStringTemplate;
return dep;
} else {
return getDep(imageName);
}
}