Skip to content

Commit ecc796f

Browse files
authored
feat: remove tags difference [CLK-493280] (#26)
Fixes #CLK-493280 Library version tags introduced noise on `cdk-diff` outputs on PRs, diminishing the capability to review stack changes on comments quickly. E.g: <https://github.com/time-loop/content-processor-cdk/pull/57#issuecomment-2081746467>. This PR removes Tags diff with regex and also adds a note in case of tags diff so that the reviewer can find the complete diff output in GH actions logs.
1 parent 4d05d27 commit ecc796f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/parsingLogic.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const STACK_REMOVAL_REGEX: [RegExp, string][] = [
2020
'',
2121
],
2222
];
23+
const STACK_TAGS_REMOVAL_REGEX: [RegExp, string][] = [
24+
[new RegExp('.*\\[~] Tags([\\s\\S]*?)(?=\\[~] AWS|\n\n)', 'gm'), ' └─ [~] Tags ...truncated\n'],
25+
];
2326

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

5154
if (!cleanStackDetails.includes('There were no differences')) {
55+
const cleanStackVersionTags = cleanCDKTagsDiffForSingleStack(cleanStackDetails);
5256
cdkLogParts.push(stackName);
53-
cdkLogParts.push(`${cleanStackDetails}\n`);
57+
if (!cleanStackVersionTags.includes('There were no tags differences')) {
58+
cdkLogParts.push(`${cleanStackVersionTags}Review cdk-diff job logs for full tags diff output !!!\n`);
59+
} else {
60+
cdkLogParts.push(`${cleanStackDetails}\n`);
61+
}
5462
}
5563
}
5664
return cdkLogParts.join('\n');
@@ -62,6 +70,17 @@ function separateDiffLogIntoStacks(log: string) {
6270
return stacks.map((_, i) => (i % 2 === 0 ? '' : stacks[i - 1] + stacks[i])).filter((e) => e);
6371
}
6472

73+
function cleanCDKTagsDiffForSingleStack(log: string) {
74+
if (!log.match(new RegExp('.*\\[~] Tags([\\s\\S]*?)(?=\\[~] AWS|\n\n)', 'gm'))) {
75+
return 'There were no tags differences';
76+
}
77+
let cleanDiff = log;
78+
for (const [regex, replacer] of STACK_TAGS_REMOVAL_REGEX) {
79+
cleanDiff = cleanDiff.replace(regex, replacer);
80+
}
81+
return cleanDiff;
82+
}
83+
6584
export function loadCdkDiffLog(filePath: string) {
6685
return fs.readFileSync(filePath, 'utf8');
6786
}

0 commit comments

Comments
 (0)