(gitlabData: any, opts: ParserIncludesInitOptions)
| 72 | } |
| 73 | |
| 74 | static async init (gitlabData: any, opts: ParserIncludesInitOptions): Promise<any[]> { |
| 75 | const {argv, inputs: inputsConfig} = opts; |
| 76 | const fileInputs = inputsConfig._file ?? {}; |
| 77 | const cliGlobalInputs = inputsConfig._cliGlobal ?? {}; |
| 78 | const cliComponentInputs = inputsConfig._cliComponents ?? {}; |
| 79 | |
| 80 | const isStructured = Utils.isStructuredInputsFile(fileInputs); |
| 81 | const globalInputs = {...Utils.getGlobalFileInputs(fileInputs), ...cliGlobalInputs}; |
| 82 | this.count++; |
| 83 | assert( |
| 84 | this.count <= opts.maximumIncludes + 1, // 1st init call is not counted |
| 85 | chalk`This GitLab CI configuration is invalid: Maximum of {blueBright ${opts.maximumIncludes}} nested includes are allowed!. This limit can be increased with the --maximum-includes cli flags.`, |
| 86 | ); |
| 87 | let includeDatas: any[] = []; |
| 88 | const promises = []; |
| 89 | const {stateDir, cwd, fetchIncludes, gitData, expandVariables, writeStreams} = opts; |
| 90 | // cache the parsed component, because parseIncludeComponent is expensive and we would call it twice otherwise |
| 91 | const componentParseCache = new Map<number, ParsedComponent>(); |
| 92 | |
| 93 | const include = this.expandInclude(gitlabData?.include, opts.variables); |
| 94 | |
| 95 | this.normalizeTriggerInclude(gitlabData, opts); |
| 96 | // Find files to fetch from remote and place in .gitlab-ci-local/includes |
| 97 | for (const [index, value] of include.entries()) { |
| 98 | if (value["rules"]) { |
| 99 | const include_rules = value["rules"]; |
| 100 | const rulesResult = Utils.getRulesResult({argv, cwd, rules: include_rules, variables: opts.variables}, gitData); |
| 101 | if (rulesResult.when === "never") { |
| 102 | continue; |
| 103 | } |
| 104 | } |
| 105 | if (value["file"]) { |
| 106 | for (const fileValue of Array.isArray(value["file"]) ? value["file"] : [value["file"]]) { |
| 107 | promises.push(this.downloadIncludeProjectFile(opts, value["project"], value["ref"] || "HEAD", fileValue)); |
| 108 | } |
| 109 | } else if (value["template"]) { |
| 110 | const {project, ref, file, domain} = this.covertTemplateToProjectFile(value["template"]); |
| 111 | const url = `https://${domain}/${project}/-/raw/${ref}/${file}`; |
| 112 | promises.push(this.downloadIncludeRemote(cwd, stateDir, url, fetchIncludes, writeStreams)); |
| 113 | } else if (value["remote"]) { |
| 114 | promises.push(this.downloadIncludeRemote(cwd, stateDir, value["remote"], fetchIncludes, writeStreams)); |
| 115 | } else if (value["component"]) { |
| 116 | const component = this.parseIncludeComponent(value["component"], gitData); |
| 117 | componentParseCache.set(index, component); |
| 118 | if (!component.isLocal) |
| 119 | { |
| 120 | promises.push(this.downloadIncludeComponent(opts, component.projectPath, component.effectiveRef, component.componentPath)); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | await Promise.all(promises); |
| 127 | |
| 128 | for (const [index, value] of include.entries()) { |
| 129 | if (value["rules"]) { |
| 130 | const include_rules = value["rules"]; |
| 131 | const rulesResult = Utils.getRulesResult({argv, cwd, rules: include_rules, variables: opts.variables}, gitData); |
nothing calls this directly
no test coverage detected