Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 16, 2025

This PR implements a new FieldCalculationMap that enables mathematical calculations on numeric fields during Azure DevOps work item migrations using NCalc expressions.

Changes Made

Core Implementation

  • Added FieldCalculationMapOptions in MigrationTools project with:

    • expression: NCalc-compatible formula (e.g., "[x]*2")
    • parameters: Dictionary mapping variable names to source field reference names
    • targetField: Destination field reference name
    • ApplyTo: Optional list of work item types (inherited from base class)
  • Added FieldCalculationMap in MigrationTools.Clients.TfsObjectModel project with:

    • Safe NCalc expression evaluation with error handling
    • Field existence validation for both source and target fields
    • Support for numeric field types (int, long, double, decimal)
    • Automatic type conversion for target field compatibility
    • Comprehensive logging for debugging and error reporting

Dependencies

  • Added ncalc v1.3.8 package to Directory.Packages.props
  • Referenced ncalc in MigrationTools.Clients.TfsObjectModel project

Testing

  • Created comprehensive unit tests (FieldCalculationMapTests) covering:
    • Configuration validation and setup
    • NCalc expression evaluation (simple, complex, division, math functions)
    • Error handling for invalid expressions and undefined variables
    • All 8 new tests pass successfully

Usage Example

{
  "FieldMapType": "FieldCalculationMap",
  "ApplyTo": ["Bug", "Task"],
  "expression": "[effort] * [rate]",
  "parameters": {
    "effort": "Custom.EstimatedHours",
    "rate": "Custom.HourlyRate"
  },
  "targetField": "Custom.EstimatedCost"
}

Technical Details

  • Safe Evaluation: Uses NCalc's synchronous evaluation to prevent security issues
  • Field Validation: Validates all referenced fields exist before attempting calculations
  • Type Safety: Converts numeric types appropriately for target field compatibility
  • Error Resilience: Gracefully handles missing fields, invalid expressions, and type conversion errors with detailed logging
  • Architecture Compliance: Follows existing FieldMap patterns and naming conventions

Testing Results

  • ✅ All projects build successfully
  • ✅ All existing tests continue to pass (25 tests)
  • ✅ New unit tests validate core functionality (8 tests)
  • ✅ No breaking changes to existing functionality

Fixes #2745.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add New FieldCalculationMap FieldMap Using NCalc for Integer Computation Add New FieldCalculationMap FieldMap Using NCalc for Integer Computation Jun 16, 2025
Copilot AI requested a review from MrHinsh June 16, 2025 10:16
Introduce new documentation files for the FieldCalculationMap
configuration in YAML and Markdown formats. These documents provide
detailed configuration samples and descriptions for the
FieldCalculationMapOptions class, which performs mathematical
calculations on numeric fields using NCalc expressions during
migration.

The addition of these documents aims to improve user understanding
and ease the configuration process for the FieldCalculationMap
feature. By providing clear examples and descriptions, users can
better utilize this feature in their migration tools setup.
@MrHinsh MrHinsh marked this pull request as ready for review June 16, 2025 11:43
@MrHinsh MrHinsh enabled auto-merge June 16, 2025 11:43
@MrHinsh MrHinsh merged commit eb60426 into main Jun 16, 2025
11 checks passed
@MrHinsh MrHinsh deleted the copilot/fix-2745 branch June 16, 2025 11:51
@nkdagility-actions-bot
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://blue-river-093197403-2746.westeurope.5.azurestaticapps.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add New FieldCalculationMap FieldMap Using NCalc for Integer Computation

2 participants