-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for case function #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for a new case expression function that provides conditional evaluation similar to a switch/case or if-else-if chain. The function accepts an odd number of arguments: pairs of boolean predicates and their corresponding results, plus a default value.
- Implements the
Casefunction in multiple expression namespaces (GitHub.Actions.Expressions and GitHub.DistributedTask.Expressions2) - Adds an
AllowCaseFunctionflag to control whether the case function is available in specific contexts - Includes parser-level validation to ensure the case function receives an odd number of parameters
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Sdk/Expressions/Sdk/Functions/Case.cs | New implementation of the Case function for GitHub Actions expressions |
| src/Sdk/DTExpressions2/Expressions2/Sdk/Functions/Case.cs | Duplicate Case function implementation for DistributedTask expressions |
| src/Sdk/Expressions/ExpressionConstants.cs | Registers the case function with min 3 and max 255 parameters |
| src/Sdk/DTExpressions2/Expressions2/ExpressionConstants.cs | Registers the case function in DTExpressions2 namespace |
| src/Sdk/Expressions/ParseExceptionKind.cs | Adds EvenParameters exception type for case function validation |
| src/Sdk/DTExpressions2/Expressions2/ParseExceptionKind.cs | Adds EvenParameters exception type in DTExpressions2 |
| src/Sdk/Expressions/ParseException.cs | Adds error message for even parameter count |
| src/Sdk/DTExpressions2/Expressions2/ParseException.cs | Adds error message for even parameter count in DTExpressions2 |
| src/Sdk/Expressions/ExpressionParser.cs | Adds allowCaseFunction parameter and validation logic for even parameters |
| src/Sdk/DTExpressions2/Expressions2/ExpressionParser.cs | Adds allowCaseFunction parameter and validation logic in DTExpressions2 |
| src/Sdk/WorkflowParser/ObjectTemplating/TemplateContext.cs | Adds AllowCaseFunction property defaulting to true |
| src/Sdk/DTObjectTemplating/ObjectTemplating/TemplateContext.cs | Adds AllowCaseFunction property in DTObjectTemplating |
| src/Sdk/WorkflowParser/ObjectTemplating/Tokens/TemplateToken.cs | Passes AllowCaseFunction to expression parser in 4 evaluation methods |
| src/Sdk/DTObjectTemplating/ObjectTemplating/Tokens/TemplateToken.cs | Passes AllowCaseFunction to expression parser in 4 evaluation methods |
| src/Sdk/WorkflowParser/Conversion/WorkflowTemplateConverter.cs | Passes AllowCaseFunction when converting if conditions |
| src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs | Passes AllowCaseFunction when converting if conditions |
| src/Runner.Worker/ActionManifestManager.cs | Disables case function for action manifest parsing |
| src/Runner.Worker/ActionManifestManagerLegacy.cs | Disables case function for legacy action manifest parsing |
| { | ||
| static ExpressionConstants() | ||
| { | ||
| AddFunction<Case>("case", 3, Byte.MaxValue); |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new case function lacks test coverage. Based on the coding guidelines for this repository, changes should be accompanied by non-trivial tests that meaningfully exercise the core functionality. Tests should be added to validate the case function with:
- Correct odd number of arguments (predicate-result pairs plus default)
- Validation that even number of arguments throws an error
- Boolean predicate evaluation
- Proper return values for matched predicates
- Default value when no predicates match
- Error handling for non-boolean predicates
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.