Skip to content

Conversation

zampierilucas
Copy link

@zampierilucas zampierilucas commented Sep 8, 2025

Summary

This PR introduces automatic display name field mapping for JIRA custom fields.

Motivation

For years, working with JIRA custom fields has been painful due to the cryptic field naming convention. When fetching issues, custom fields are returned as customfield_12345 instead of their meaningful display names like "Epic Link" or "Story Points". This forces developers to:

  • Maintain internal mappings between field IDs and display names
  • Constantly convert between cryptic IDs and readable names
  • Write brittle code that breaks when field IDs change

For example, this public JIRA issue showing the custom field structure that I have to deal with:
https://issues.redhat.com/rest/api/2/issue/RHEL-12345?expand=names

Proposed solution

This PR adds transparent display name field mapping that allows both access patterns:

# Before: Only cryptic field IDs
issue.fields.customfield_10001  # Maps to "EPIC-LINK" -> "EPIC-123"

# After: Both cryptic IDs AND readable names work
issue.fields.customfield_10001  # "EPIC-LINK" -> "EPIC-123" (backwards compatible)
issue.fields.epic_link          # "EPIC-LINK" -> "EPIC-123" (new readable access)

Key consideration

  • Backwards Compatible: All existing code continues to work unchanged, customfields_ are still there
  • Automatic: Field mappings are automatically detected from _fields_cache
  • Transparent: Display name fields are created during initial JSON parsing
  • Collision Safe: Won't overwrite existing attributes

Benefits

  • Developer Experience: Dramatically improves code readability and maintainability
  • Self-Documenting: Field names clearly indicate their purpose
  • IDE Support: Better autocomplete and intellisense
  • Reduced Errors: Less chance of using wrong field IDs
  • Future Proof: Adapts automatically to JIRA configuration changes

Testing

  • New tests added for the new functionality and backwards compatibility

Enable access to custom fields using readable display names in addition to field IDs.
Users can access fields like issue.fields.epic_link alongside issue.fields.customfield_10001.

- Add display name fields during JSON parsing in dict2resource()
- Convert display names to valid Python identifiers (e.g. 'Epic Link' -> 'epic_link')
- Only create mappings for fields present in API response
- Maintain full backwards compatibility with existing field ID access

Signed-off-by: Lucas Zampieri <lzampier@redhat.com>
Add test coverage for display name field mapping functionality:

- Unit tests for field name conversion logic
- Integration tests with real JIRA data
- Mock tests for controlled edge case validation
- Issue-specific behavior testing
- Backwards compatibility verification
- Field equivalence validation

Tests cover:
- Basic field name conversion (Epic Link -> epic_link)
- Special character handling and numeric prefixes
- Name collision prevention and duplicate field detection
- Empty/None value handling and missing field cache scenarios
- Performance impact validation

Signed-off-by: Lucas Zampieri <lzampier@redhat.com>
Comment on lines +677 to +678
# Store fields cache reference on session for display name field injection
self._session.fields_cache = self._fields_cache
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a hack to me, but I could not find a way to access _fields_cache from resources directly, but I would love to be pointed in the 'right' way to do it.

@derekbarbosa
Copy link

adding a comment here for visibility -- this would be immensely useful in plenty of enterprise applications where custom fields are used in various automation purposes (such as webhooks, push events, etc, on various forges/CI systems). It is immensely painful to keep track of customfields at the moment, especially as their IDs can change across projects.

@studioj
Copy link
Collaborator

studioj commented Sep 13, 2025

thanks a lot for the contribution, currently extension of the module though is a bit on hold until we get a grasp on the CI system and test runners . as you can see we're only testing an old version of jira datacenter. We'd really want to make sure our cloud part is up and running too before we start again with the extension with awesome functionality ...
The little time I have will be spent making this ready and indeed :-) i feel your same pain

@studioj
Copy link
Collaborator

studioj commented Sep 13, 2025

adding a comment here for visibility -- this would be immensely useful in plenty of enterprise applications where custom fields are used in various automation purposes (such as webhooks, push events, etc, on various forges/CI systems). It is immensely painful to keep track of customfields at the moment, especially as their IDs can change across projects.

@derekbarbosa you're invited to do extra manual validation on this branch ... this would increase trust in the PR itself,
Thank you

@studioj
Copy link
Collaborator

studioj commented Sep 13, 2025

thanks a lot for the contribution, currently extension of the module though is a bit on hold until we get a grasp on the CI system and test runners . as you can see we're only testing an old version of jira datacenter. We'd really want to make sure our cloud part is up and running too before we start again with the extension with awesome functionality ... The little time I have will be spent making this ready and indeed :-) i feel your same pain

I'm trying to get some basic cloud tests already up, maybe yours can be added

@studioj
Copy link
Collaborator

studioj commented Sep 13, 2025

@zampierilucas could you also extend the examples in the docs?
please dont use epic_link as example though as it is deprecated

…epic_link

- Add custom field display name mapping section to docs/examples.rst
- Replace deprecated epic_link examples with story_points
- Update test cases to use current non-deprecated field examples

Signed-off-by: Lucas Zampieri <lzampier@redhat.com>
@zampierilucas
Copy link
Author

Hi @studioj, thanks for the feedback, I've added both the docs and updated the "Epic links" to a new field as you suggested.
And yes, regarding the cloud test, you can use my integrations tests, just have to set up all the CI_JIRA_* env variables.

@studioj
Copy link
Collaborator

studioj commented Sep 15, 2025

Hi @studioj, thanks for the feedback, I've added both the docs and updated the "Epic links" to a new field as you suggested.
And yes, regarding the cloud test, you can use my integrations tests, just have to set up all the CI_JIRA_* env variables.

I'm prepping a branch to test more on cloud, maybe a review.and.some comments can help getting it through faster

@derekbarbosa
Copy link

adding a comment here for visibility -- this would be immensely useful in plenty of enterprise applications where custom fields are used in various automation purposes (such as webhooks, push events, etc, on various forges/CI systems). It is immensely painful to keep track of customfields at the moment, especially as their IDs can change across projects.

@derekbarbosa you're invited to do extra manual validation on this branch ... this would increase trust in the PR itself, Thank you

sorry for the delay.

manual review LGTM. the self-described hack follows a similar convention to the existing _fields_cache property which returns _fields_cache_value.

trying to run the tox tests in my local env errors out, most likely due to some settings in my immutable-distro setup... will post results if I manage to get it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants