diff --git a/dist/index.js b/dist/index.js index bd93d46..34cc27b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -110,6 +110,9 @@ class GraphBuilder { graphNode = { value: issue, predecessors: [], successors: [] }; this.nodes.set(nodeKey, graphNode); } + else if (issue) { + graphNode.value = issue; + } return graphNode; } addIssue(issueReference, issue) { diff --git a/src/graph-builder.ts b/src/graph-builder.ts index 8c9bb20..6123f88 100644 --- a/src/graph-builder.ts +++ b/src/graph-builder.ts @@ -33,6 +33,8 @@ export class GraphBuilder { if (!graphNode) { graphNode = { value: issue, predecessors: [], successors: [] }; this.nodes.set(nodeKey, graphNode); + } else if (issue) { + graphNode.value = issue; } return graphNode; diff --git a/tests/graph-builder.test.ts b/tests/graph-builder.test.ts index cac7414..4a89e2c 100644 --- a/tests/graph-builder.test.ts +++ b/tests/graph-builder.test.ts @@ -197,4 +197,29 @@ describe("GraphBuilder", () => { { from: "issue3", to: "finish" }, ]); }); + + it("Add dependency before adding node", () => { + const graphBuilder = new GraphBuilder(true); + + graphBuilder.addIssue( + { repoOwner: "A", repoName: "B", issueNumber: 1 }, + new MermaidNode("issue1", "Test issue 1", "notstarted") + ); + graphBuilder.addDependency( + { repoOwner: "A", repoName: "B", issueNumber: 1 }, + { repoOwner: "A", repoName: "B", issueNumber: 2 } + ); + graphBuilder.addIssue( + { repoOwner: "A", repoName: "B", issueNumber: 2 }, + new MermaidNode("issue2", "Test issue 2", "started") + ); + + const actual = extractNodeIdFromGraph(graphBuilder.getGraph()); + expect(actual.vertices).toEqual(["start", "issue1", "issue2", "finish"]); + expect(actual.edges).toEqual([ + { from: "start", to: "issue1" }, + { from: "issue1", to: "issue2" }, + { from: "issue2", to: "finish" }, + ]); + }); });