Skip to content

Commit d91512c

Browse files
committed
Improvments to parse csv
1 parent bddb578 commit d91512c

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

server-build/src/normalizer/utils.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,21 @@ export const normalizeCapabilityLevel = (capability: string) => {
4343
* @param operator
4444
*/
4545
const getExampleYAML = (kind: string, operator: Operator): AlmExample| null => {
46-
const examples: string = get(operator, 'metadata.annotations.alm-examples');
46+
// const examples: string = get(operator, 'metadata.annotations.alm-examples');
47+
const examples_: string = get(operator, 'metadata.annotations.alm-examples');
48+
if (examples_) {
49+
let regex = /\,(?!\s*?[\{\[\"\'\w])/g;
50+
let examples = examples_.replace(regex, '');
4751

48-
if (examples) {
49-
try {
50-
const yamlExamples: any[] = JSON.parse(examples);
51-
return yamlExamples.find(example => example.kind === kind);
52+
if (examples) {
53+
try {
54+
const yamlExamples: any[] = JSON.parse(examples);
55+
return yamlExamples.find(example => example.kind === kind);
5256

53-
} catch (e) {
54-
Logger.error(`getExampleYAML > failed to parse example for CRD ${kind}`, e);
57+
} catch (e) {
58+
Logger.error(`getExampleYAML > failed to parse example for CRD ${kind}`, e);
59+
process.exit(1);
60+
}
5561
}
5662
}
5763
return null;

server/src/importer/normalizer/utils.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,25 @@ export const normalizeCapabilityLevel = (capability: string) => {
4343
* @param operator
4444
*/
4545
const getExampleYAML = (kind: string, operator: Operator): AlmExample| null => {
46-
const examples: string = get(operator, 'metadata.annotations.alm-examples');
46+
const examples_: string = get(operator, 'metadata.annotations.alm-examples');
47+
if (examples_) {
48+
let regex = /\,(?!\s*?[\{\[\"\'\w])/g;
49+
let examples = examples_.replace(regex, '');
4750

48-
if (examples) {
49-
try {
50-
const yamlExamples: any[] = JSON.parse(examples);
51-
return yamlExamples.find(example => example.kind === kind);
51+
if (examples) {
52+
try {
53+
const yamlExamples: any[] = JSON.parse(examples);
54+
return yamlExamples.find(example => example.kind === kind);
5255

53-
} catch (e) {
54-
Logger.error(`getExampleYAML > failed to parse example for CRD ${kind}`, e);
56+
} catch (e) {
57+
Logger.error(`getExampleYAML > failed to parse example for CRD ${kind}`, e);
58+
}
5559
}
5660
}
5761
return null;
5862
};
5963

64+
6065
/**
6166
* Normalize single CRD
6267
* @param crd

0 commit comments

Comments
 (0)