mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
refactor(javascript): count version comparison outcomes together (#16057)
This commit is contained in:
1 parent
ac13b8f3a6
commit
345caadc6c
1 file changed
+31
-41
@@ -70,8 +70,7 @@ export const compareJavaScriptApplicationVersions = (
|
||||
graph_id: input.right.graph.graph_id,
|
||||
root_artifact_sha256: input.right.rootArtifactSha256,
|
||||
},
|
||||
summary: summary(projection.items),
|
||||
matching: matchingSummary(projection.items),
|
||||
...comparisonCounts(projection.items),
|
||||
items: projection.items,
|
||||
graph: changeGraph.graph,
|
||||
coverage,
|
||||
@@ -84,24 +83,34 @@ export const compareJavaScriptApplicationVersions = (
|
||||
});
|
||||
};
|
||||
|
||||
const summary = (
|
||||
items: readonly ApplicationVersionComparisonResult["items"][number][],
|
||||
): ApplicationVersionComparisonResult["summary"] => {
|
||||
const counts = {
|
||||
type ComparisonItem = ApplicationVersionComparisonResult["items"][number];
|
||||
|
||||
const MATCH_COUNT_FIELD = {
|
||||
"exact-node-identity": "exact_node_identity",
|
||||
"exact-content-digest": "exact_content_digest",
|
||||
"exact-module-source-digest": "exact_module_source_digest",
|
||||
"source-map-identity": "source_map_identity",
|
||||
"structural-fingerprint": "structural_fingerprint",
|
||||
"semantic-key": "semantic_key",
|
||||
} as const satisfies Record<
|
||||
Extract<ComparisonItem["match"], { status: "matched" }>["basis"],
|
||||
Exclude<
|
||||
keyof ApplicationVersionComparisonResult["matching"],
|
||||
"ambiguous" | "unmatched"
|
||||
>
|
||||
>;
|
||||
|
||||
const comparisonCounts = (
|
||||
items: readonly ComparisonItem[],
|
||||
): Pick<ApplicationVersionComparisonResult, "summary" | "matching"> => {
|
||||
const summary = {
|
||||
unchanged: 0,
|
||||
added: 0,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 0,
|
||||
};
|
||||
for (const item of items) counts[item.status] += 1;
|
||||
return counts;
|
||||
};
|
||||
|
||||
const matchingSummary = (
|
||||
items: readonly ApplicationVersionComparisonResult["items"][number][],
|
||||
): ApplicationVersionComparisonResult["matching"] => {
|
||||
const counts = {
|
||||
const matching = {
|
||||
exact_node_identity: 0,
|
||||
exact_content_digest: 0,
|
||||
exact_module_source_digest: 0,
|
||||
@@ -111,34 +120,15 @@ const matchingSummary = (
|
||||
ambiguous: 0,
|
||||
unmatched: 0,
|
||||
};
|
||||
for (const { match } of items) {
|
||||
switch (match.basis) {
|
||||
case "exact-node-identity":
|
||||
counts.exact_node_identity += 1;
|
||||
break;
|
||||
case "exact-content-digest":
|
||||
counts.exact_content_digest += 1;
|
||||
break;
|
||||
case "exact-module-source-digest":
|
||||
counts.exact_module_source_digest += 1;
|
||||
break;
|
||||
case "source-map-identity":
|
||||
counts.source_map_identity += 1;
|
||||
break;
|
||||
case "structural-fingerprint":
|
||||
counts.structural_fingerprint += 1;
|
||||
break;
|
||||
case "semantic-key":
|
||||
counts.semantic_key += 1;
|
||||
break;
|
||||
case "none":
|
||||
// Ambiguous and unmatched items are counted by match status below.
|
||||
break;
|
||||
}
|
||||
if (match.status === "ambiguous") counts.ambiguous += 1;
|
||||
else if (match.status === "unmatched") counts.unmatched += 1;
|
||||
for (const { status, match } of items) {
|
||||
summary[status] += 1;
|
||||
const field =
|
||||
match.status === "matched"
|
||||
? MATCH_COUNT_FIELD[match.basis]
|
||||
: match.status;
|
||||
matching[field] += 1;
|
||||
}
|
||||
return counts;
|
||||
return { summary, matching };
|
||||
};
|
||||
|
||||
type ComparisonOmissions = ApplicationVersionComparisonResult["coverage"];
|
||||
|
||||
Reference in new issue
Block a user