( oldBuildParameters: TypesGen.WorkspaceBuildParameter[], newBuildParameters: TypesGen.WorkspaceBuildParameter[], templateParameters: TypesGen.TemplateVersionParameter[], )
| 39 | import * as TypesGen from "./typesGenerated"; |
| 40 | |
| 41 | const getMissingParameters = ( |
| 42 | oldBuildParameters: TypesGen.WorkspaceBuildParameter[], |
| 43 | newBuildParameters: TypesGen.WorkspaceBuildParameter[], |
| 44 | templateParameters: TypesGen.TemplateVersionParameter[], |
| 45 | ) => { |
| 46 | const missingParameters: TypesGen.TemplateVersionParameter[] = []; |
| 47 | const requiredParameters: TypesGen.TemplateVersionParameter[] = []; |
| 48 | |
| 49 | for (const p of templateParameters) { |
| 50 | // It is mutable and required. Mutable values can be changed after so we |
| 51 | // don't need to ask them if they are not required. |
| 52 | const isMutableAndRequired = p.mutable && p.required; |
| 53 | // Is immutable, so we can check if it is its first time on the build |
| 54 | const isImmutable = !p.mutable; |
| 55 | |
| 56 | if (isMutableAndRequired || isImmutable) { |
| 57 | requiredParameters.push(p); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | for (const parameter of requiredParameters) { |
| 62 | // Check if there is a new value |
| 63 | let buildParameter = newBuildParameters.find( |
| 64 | (p) => p.name === parameter.name, |
| 65 | ); |
| 66 | |
| 67 | // If not, get the old one |
| 68 | if (!buildParameter) { |
| 69 | buildParameter = oldBuildParameters.find( |
| 70 | (p) => p.name === parameter.name, |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | // If there is a value from the new or old one, it is not missed |
| 75 | if (buildParameter) { |
| 76 | continue; |
| 77 | } |
| 78 | |
| 79 | missingParameters.push(parameter); |
| 80 | } |
| 81 | |
| 82 | // Check if parameter "options" changed and we can't use old build parameters. |
| 83 | for (const templateParameter of templateParameters) { |
| 84 | if (templateParameter.options.length === 0) { |
| 85 | continue; |
| 86 | } |
| 87 | // For multi-select, extra steps are necessary to JSON parse the value. |
| 88 | if (templateParameter.form_type === "multi-select") { |
| 89 | continue; |
| 90 | } |
| 91 | let buildParameter = newBuildParameters.find( |
| 92 | (p) => p.name === templateParameter.name, |
| 93 | ); |
| 94 | |
| 95 | // If not, get the old one |
| 96 | if (!buildParameter) { |
| 97 | buildParameter = oldBuildParameters.find( |
| 98 | (p) => p.name === templateParameter.name, |
no test coverage detected