Skip to content

Commit c24457b

Browse files
authored
Fix connections for sequential nested stages (#1291)
1 parent a609339 commit c24457b

4 files changed

Lines changed: 1161 additions & 31 deletions

File tree

src/main/frontend/pipeline-graph-view/pipeline-graph/main/NestedPipelineGraphLayout.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ describe("NestedPipelineGraphLayout", () => {
7474
shouldMatchSnapshot(raw, true);
7575
});
7676
});
77+
78+
describe("gh1286_wrapped_all_skipped.jenkinsfile", () => {
79+
const raw =
80+
'[{"name":"Wrapper","state":"success","id":"4","type":"STAGE","children":[{"name":"Skipped 1","state":"skipped","id":"6","type":"STAGE","children":[]},{"name":"Skipped 2","state":"skipped","id":"10","type":"STAGE","children":[]}]},{"name":"Next","state":"success","id":"16","type":"STAGE","children":[]}]';
81+
82+
it("should render layout", () => {
83+
shouldMatchSnapshot(raw, false);
84+
});
85+
it("should render collapsed layout", () => {
86+
shouldMatchSnapshot(raw, true);
87+
});
88+
});
7789
});
7890
});
7991

src/main/frontend/pipeline-graph-view/pipeline-graph/main/NestedPipelineGraphLayout.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ function computeTailNodes(
363363
// Collect nodes in a Set. With two skipped nodes next to each other, we need to deduplicate them.
364364
const sourceNodes = new Set<GraphNode>();
365365
const skippedNodes = new Set<GraphNode>();
366+
const resolveDestination = (node: GraphNode): GraphNode[] => {
367+
if (node.hasParallel) {
368+
// Connect directly to parallel children
369+
return node.children;
370+
}
371+
if (node.children.length > 0) {
372+
// Connect directly to 1st child, recusively resolve it.
373+
return resolveDestination(node.children[0]);
374+
}
375+
return [node];
376+
};
366377
const connect = (
367378
tailNodes: GraphNode[],
368379
destination: GraphNode,
@@ -375,9 +386,7 @@ function computeTailNodes(
375386
skippedNodes.add(node);
376387
}
377388
}
378-
const destinationNodes = destination.hasParallel
379-
? destination.children // Connect directly to parallel children
380-
: [destination];
389+
const destinationNodes = resolveDestination(destination);
381390
if (!destinationNodes.some((n) => !n.isSkipped)) {
382391
for (const node of destinationNodes) skippedNodes.add(node);
383392
return;
@@ -391,7 +400,8 @@ function computeTailNodes(
391400
sourceNodes.clear();
392401
skippedNodes.clear();
393402
};
394-
if (node.type !== "root") {
403+
if (node.isParallel) {
404+
// Non-parallel stages will have been connected already via resolveDestination.
395405
connect([node], node.children[0], true);
396406
}
397407
for (let i = 0; i < node.children.length - 1; i++) {
@@ -405,7 +415,10 @@ function computeTailNodes(
405415
);
406416
}
407417
const last = node.children[node.children.length - 1];
408-
if (last.isSkipped || skippedNodes.size > 0 || sourceNodes.size > 0) {
418+
if (last.isSkipped) {
419+
return [...sourceNodes, ...skippedNodes, last];
420+
}
421+
if (skippedNodes.size > 0 || sourceNodes.size > 0) {
409422
throw new Error("bug: buildGraphNested did not add trailing dummy node");
410423
}
411424
return computeTailNodes(connections, last);

0 commit comments

Comments
 (0)