-
Notifications
You must be signed in to change notification settings - Fork 210
feat: added parsing and interpolation for component.* variables #1839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ae20b31
f919e7f
04a1e1f
36e5670
022bea9
f9c3b3a
d9852a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,7 +328,7 @@ export class Parser { | |
| const inputsSpecification: any = fileData[0]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be also be parsed for |
||
| const uninterpolatedConfigurations: any = fileData[1]; | ||
|
|
||
| const interpolatedConfigurations = JSON.stringify(uninterpolatedConfigurations) | ||
| const configurationWithInterpolatedInputs = JSON.stringify(uninterpolatedConfigurations) | ||
| .replaceAll( | ||
| /(?<firstChar>.)?(?<secondChar>.)?\$\[\[\s*inputs.(?<interpolationKey>[\w-]+)\s*\|?\s*(?<interpolationFunctions>.*?)\s*\]\](?<lastChar>[^$])?/g // https://regexr.com/81c16 | ||
| , (_: string, firstChar: string, secondChar: string, interpolationKey: string, interpolationFunctions: string, lastChar: string) => { | ||
|
|
@@ -372,7 +372,37 @@ export class Parser { | |
| Utils.switchStatementExhaustiveCheck(inputType); | ||
| } | ||
| }); | ||
| return JSON.parse(interpolatedConfigurations); | ||
|
|
||
| // NOTE: Replacement of the component interpolation keys behaves slightly different. It currently does not check whether the interpolation key | ||
| // is specified in the specs via component: [{interpolationKey}, ...] | ||
| const configurationWithInterpolatedInputsAndComponent = configurationWithInterpolatedInputs | ||
| .replaceAll( | ||
| /(?<firstChar>.)?(?<secondChar>.)?\$\[\[\s*component.(?<interpolationKey>[\w-]+)\s*\]\](?<lastChar>[^$])?/g, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| (_, firstChar, secondChar, interpolationKey, lastChar) => { | ||
| firstChar ??= ""; | ||
| secondChar ??= ""; | ||
| lastChar ??= ""; | ||
|
|
||
| const { component } = ctx; | ||
| if (!component) return _; | ||
|
|
||
| let componentValue | ||
| const properties = [ "name", "reference", "version", "sha" ]; | ||
| let foundKey = false; | ||
| properties.forEach(property => { | ||
| if (property === interpolationKey) { | ||
| foundKey = true; | ||
| componentValue = component[interpolationKey]; | ||
| } | ||
| }) | ||
|
|
||
| assert(foundKey, chalk`This GitLab CI configuration is invalid: \`{blueBright ${ctx.configFilePath}}\`: unknown interpolation key: \`${interpolationKey}\`.`); | ||
| return firstChar + secondChar + componentValue + lastChar; | ||
| } | ||
| ); | ||
|
|
||
|
|
||
| return JSON.parse(configurationWithInterpolatedInputsAndComponent); | ||
| } | ||
| return fileData[0]; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.