Skip to content

Commit

Permalink
feat: Add start node for PUML format
Browse files Browse the repository at this point in the history
Signed-off-by: Sergiy Kulanov <[email protected]>
  • Loading branch information
SergK committed Oct 8, 2023
1 parent 74e7618 commit fe6ed13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/taskgraph/taskgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (g *TaskGraph) ToPlantUML() string {
// Replace dashes with underscores in node names because PlantUML doesn't like dashes
nodeName := strings.ReplaceAll(node.Name, "-", "_")
// the root node is the one with no dependencies and that task starts the execution immediately
if !node.hasParent {
plantuml += fmt.Sprintf("[*] --> %s\n", nodeName)
}
if len(node.Dependencies) == 0 {
plantuml += fmt.Sprintf("%s --> [*]\n", nodeName)
}
Expand All @@ -156,6 +159,9 @@ func (g *TaskGraph) ToPlantUMLWithTaskRef() string {
// Replace dashes with underscores in node names because PlantUML doesn't like dashes
nodeName := strings.ReplaceAll(node.Name, "-", "_")
// the root node is the one with no dependencies and that task starts the execution immediately
if !node.hasParent {
plantuml += fmt.Sprintf("[*] --> %s\n", nodeName)
}
if len(node.Dependencies) == 0 {
plantuml += fmt.Sprintf("%s --> [*]\n", nodeName)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/taskgraph/taskgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func TestTaskGraphToPlantUML(t *testing.T) {
// Test the ToPlantUML method
plantuml := graph.ToPlantUML()
assert.Contains(t, plantuml, "@startuml\nhide empty description\ntitle test-pipeline\n\n")
assert.Contains(t, plantuml, "[*] --> task3\n")
assert.Contains(t, plantuml, "[*] --> task4\n")
assert.Contains(t, plantuml, "task1 --> [*]\n")
assert.Contains(t, plantuml, "task4 --> [*]\n")
assert.Contains(t, plantuml, "task2 -down-> task1\n")
Expand All @@ -157,6 +159,8 @@ func TestTaskGraphToPlantUMLWithTaskRef(t *testing.T) {
assert.Contains(t, plantuml, "@startuml\nhide empty description\ntitle test-pipeline\n\n")
assert.Contains(t, plantuml, "task1 --> [*]")
assert.Contains(t, plantuml, "task4 --> [*]")
assert.Contains(t, plantuml, "[*] --> task3\n")
assert.Contains(t, plantuml, "[*] --> task4\n")
assert.Contains(t, plantuml, "task2 -down-> task1")
assert.Contains(t, plantuml, "task3 -down-> task1")
assert.Contains(t, plantuml, "task3 -down-> task2")
Expand Down

0 comments on commit fe6ed13

Please sign in to comment.