Skip to content
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

if-diff: Ignore certain fields from manifest #796

Merged
merged 1 commit into from
Jun 11, 2024
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
47 changes: 24 additions & 23 deletions src/lib/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import {checkIfEqual, oneIsPrimitive} from '../util/helpers';

import {Difference} from '../types/lib/compare';

/**
* Returns `status` and `exception` properties from execution context.
*/
const omitExecutionParams = (object: any) => ({
status: object.status,
...(object.error && {
error: object.error,
}),
});

/**
* 1. If objects are not of the same type or are primitive types, compares directly.
* 2. Gets the keys from both objects.
Expand All @@ -36,26 +26,37 @@ export const compare = (source: any, target: any, path = ''): Difference => {

const allKeys = new Set([...keys1, ...keys2]);

if (path === '') {
allKeys.delete('name');
allKeys.delete('description');
allKeys.delete('tags');
}

if (path === 'initialize') {
allKeys.delete('outputs');
}

if (path === 'execution') {
const whitelist = ['status', 'error'];
allKeys.forEach(value => {
if (!whitelist.includes(value)) {
allKeys.delete(value);
}
});
}

if (Array.isArray(source) && Array.isArray(target)) {
source.forEach((_record, i) => {
compare(source[i], target[i], path ? `${path}[${i}]` : `${i}`);
});
}

for (const key of allKeys) {
let result: any = {};

if (key === 'execution') {
if (source[key] && target[key]) {
result = compare(
omitExecutionParams(source[key]),
omitExecutionParams(target[key]),
path ? `${path}.${key}` : key
);
}
} else {
result = compare(source[key], target[key], path ? `${path}.${key}` : key);
}
const result = compare(
source[key],
target[key],
path ? `${path}.${key}` : key
);

if (Object.keys(result).length) {
return result;
Expand Down