Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/parsingLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const STACK_REMOVAL_REGEX: [RegExp, string][] = [
'',
],
];
const STACK_TAGS_REMOVAL_REGEX: [RegExp, string][] = [
[new RegExp('.*\\[~] Tags([\\s\\S]*?)(?=\\[~] AWS|\n\n)', 'gm'), ' └─ [~] Tags ...truncated\n'],
];

function cleanCdkDiffLog(cdkLog: string) {
let cleanLog = cdkLog;
Expand Down Expand Up @@ -49,8 +52,13 @@ function rebuildDiffsIntoCdkLog(stacks: string[]) {
const cleanStackDetails = cleanCDKDiffForSingleStack(stackDetails);

if (!cleanStackDetails.includes('There were no differences')) {
const cleanStackVersionTags = cleanCDKTagsDiffForSingleStack(cleanStackDetails);
cdkLogParts.push(stackName);
cdkLogParts.push(`${cleanStackDetails}\n`);
if (!cleanStackVersionTags.includes('There were no tags differences')) {
cdkLogParts.push(`${cleanStackVersionTags}Review cdk-diff job logs for full tags diff output !!!\n`);
} else {
cdkLogParts.push(`${cleanStackDetails}\n`);
}
}
}
return cdkLogParts.join('\n');
Expand All @@ -62,6 +70,17 @@ function separateDiffLogIntoStacks(log: string) {
return stacks.map((_, i) => (i % 2 === 0 ? '' : stacks[i - 1] + stacks[i])).filter((e) => e);
}

function cleanCDKTagsDiffForSingleStack(log: string) {
if (!log.match(new RegExp('.*\\[~] Tags([\\s\\S]*?)(?=\\[~] AWS|\n\n)', 'gm'))) {
return 'There were no tags differences';
}
let cleanDiff = log;
for (const [regex, replacer] of STACK_TAGS_REMOVAL_REGEX) {
cleanDiff = cleanDiff.replace(regex, replacer);
}
return cleanDiff;
}

export function loadCdkDiffLog(filePath: string) {
return fs.readFileSync(filePath, 'utf8');
}
Expand Down