Skip to content

fix(#638): Add custom field type discovery support#639

Merged
ryancheley merged 1 commit intomainfrom
638-custom-fields-feature-only-works-with-enum-types
Mar 19, 2026
Merged

fix(#638): Add custom field type discovery support#639
ryancheley merged 1 commit intomainfrom
638-custom-fields-feature-only-works-with-enum-types

Conversation

@ryancheley
Copy link
Copy Markdown
Owner

Summary

Implement dynamic field type discovery to support all YouTrack custom field types, not just Enum types. The CLI now automatically detects field types from project configuration with intelligent fallback behavior.

Previously, the --custom-field option only worked with Enum fields because it hardcoded all custom fields as SingleEnumIssueCustomField. Non-enum fields (Text, Integer, Date, User, Version, Build, etc.) would fail with type mismatch errors.

Now, the CLI queries the project's custom field configuration to determine the actual field type and uses the appropriate field creation method. If type discovery fails, it gracefully falls back to enum type with a helpful warning.

Changes

Custom Field Manager (youtrack_cli/custom_field_manager.py)

  • Added create_simple_field() for integer/float custom fields
  • Added create_date_field() for date custom fields
  • Added create_single_version_field() for version fields
  • Added create_single_build_field() for build fields
  • Added create_field_by_type() polymorphic dispatcher that creates the appropriate field type based on discovered information

Project Service (youtrack_cli/services/projects.py)

  • Added discover_custom_field() method that:
    • Queries all project custom fields
    • Finds the field by name (case-insensitive)
    • Determines the issue field type from project field type
    • Extracts bundle element type information
    • Caches results for performance
  • Added _project_to_issue_field_type() mapping to convert between project and issue field type constants

Issue Service (youtrack_cli/services/issues.py)

  • Updated create_issue() to use field type discovery instead of hardcoding enum types
  • Updated update_issue() with identical field discovery logic
  • Added graceful fallback with warning logs when discovery fails
  • Maintains full backward compatibility with existing enum field handling

Documentation (docs/commands/issues.rst)

  • Added comprehensive custom fields section with:
    • List of all supported field types
    • Explanation of automatic type detection
    • Practical examples for each field type (enum, text, integer, user)
  • Updated both create and update command documentation

Changelog (CHANGELOG.md)

  • Documented fix with details about type discovery and fallback behavior

Supported Field Types

The --custom-field option now supports all YouTrack field types:

  • Enum (single/multi) - Team=Backend
  • Text - Notes=Implementation notes
  • Simple (integer/float) - StoryPoints=5
  • User (single/multi) - Reviewer=john.doe
  • Version (single/multi) - FixVersion=1.0
  • Build (single/multi) - Build=Release-123
  • Date/DateTime - DueDate=1234567890000
  • Period - Time period fields
  • State - Status/workflow state fields

Technical Details

Type Discovery Pattern

Follows the established pattern from discover_state_field() method:

  1. Check cache first for performance
  2. Query project custom fields API
  3. Find field by name (case-insensitive)
  4. Get detailed field information including bundle type
  5. Extract and store field metadata
  6. Cache results for subsequent operations

Fallback Behavior

If field type discovery fails for any reason:

  • Logs a warning message with the error
  • Falls back to creating an enum field (safest default)
  • Continues processing other fields
  • Does not stop the entire operation

Performance

  • Field type information is cached after first discovery
  • Subsequent operations for the same field use cached data
  • No performance regression for enum fields

Testing

  • All 1359 existing tests pass
  • All pre-commit checks pass (ruff, ty, pydocstyle, pytest)
  • Test coverage maintained at 60%

Fixes #638

Implement dynamic field type discovery to support all YouTrack custom field types,
not just Enum types. The CLI now automatically detects field types from project
configuration with proper fallback behavior.

Changes:
- Add field type discovery method discover_custom_field() to ProjectService
- Add _project_to_issue_field_type() mapping for type conversion
- Add missing field creation methods to CustomFieldManager:
  - create_simple_field() for integer/float fields
  - create_date_field() for date fields
  - create_single_version_field() for version fields
  - create_single_build_field() for build fields
  - create_field_by_type() for polymorphic field creation
- Update create_issue() and update_issue() to use field type discovery
- Add caching for discovered field types to improve performance
- Update documentation with examples for all supported field types
- Update CHANGELOG with fix details

Supported field types:
- Enum (single/multi)
- Text
- Simple (integer/float)
- User (single/multi)
- Version (single/multi)
- Build (single/multi)
- Date/DateTime
- Period
- State

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@ryancheley ryancheley linked an issue Mar 19, 2026 that may be closed by this pull request
@ryancheley ryancheley marked this pull request as ready for review March 19, 2026 03:42
@ryancheley ryancheley merged commit db293be into main Mar 19, 2026
10 checks passed
@ryancheley ryancheley deleted the 638-custom-fields-feature-only-works-with-enum-types branch March 19, 2026 03:42
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.

Custom fields feature only works with Enum types

1 participant