Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use DisjunctionNode for buildOr with 3+ conditions
- Updated buildOr to return DisjunctionNode for 3+ conditions instead of nested OrNode structures
- DisjunctionNode renders as flat OR chain (a || b || c) avoiding deep nesting
- Updated test expectations to match new flat rendering
- All tests pass successfully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
  • Loading branch information
Copilot and pelikhan committed Oct 11, 2025
commit c71032169bbd56b8343b8949d4755b2b38fefc8a
4 changes: 2 additions & 2 deletions .github/workflows/brave.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/ci-doctor.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/dev.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/pdf-summary.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/scout.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/technical-doc-writer.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/unbloat-docs.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions pkg/workflow/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func buildConditionTree(existingCondition string, draftCondition string) Conditi

// buildOr creates an OR condition from two or more condition nodes.
// When called with 2 arguments, it creates a simple OR node.
// When called with more arguments, it creates a right-associative OR tree: a || (b || (c || ...))
// When called with more arguments, it creates a DisjunctionNode to avoid deep nesting.
func buildOr(conditions ...ConditionNode) ConditionNode {
if len(conditions) == 0 {
return nil
Expand All @@ -219,12 +219,8 @@ func buildOr(conditions ...ConditionNode) ConditionNode {
return &OrNode{Left: conditions[0], Right: conditions[1]}
}

// Build a right-associative OR tree for 3+ conditions: a || (b || (c || ...))
result := conditions[len(conditions)-1]
for i := len(conditions) - 2; i >= 0; i-- {
result = &OrNode{Left: conditions[i], Right: result}
}
return result
// Use DisjunctionNode for 3+ conditions to avoid deep nesting
return &DisjunctionNode{Terms: conditions}
}

func buildAnd(left ConditionNode, right ConditionNode) ConditionNode {
Expand Down
6 changes: 3 additions & 3 deletions pkg/workflow/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func TestBuildOr(t *testing.T) {
BuildPropertyAccess("github.event.pull_request.number"),
BuildPropertyAccess("github.event.discussion.number"),
},
expected: "(github.event.issue.number) || ((github.event.pull_request.number) || (github.event.discussion.number))",
expected: "github.event.issue.number || github.event.pull_request.number || github.event.discussion.number",
},
{
name: "four conditions",
Expand All @@ -771,7 +771,7 @@ func TestBuildOr(t *testing.T) {
&ExpressionNode{Expression: "c"},
&ExpressionNode{Expression: "d"},
},
expected: "(a) || ((b) || ((c) || (d)))",
expected: "a || b || c || d",
},
{
name: "mixed node types",
Expand All @@ -780,7 +780,7 @@ func TestBuildOr(t *testing.T) {
BuildEventTypeEquals("pull_request"),
BuildPropertyAccess("github.event.issue.number"),
},
expected: "(github.event.action == 'opened') || ((github.event_name == 'pull_request') || (github.event.issue.number))",
expected: "github.event.action == 'opened' || github.event_name == 'pull_request' || github.event.issue.number",
},
}

Expand Down
Loading