You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While this library is fantastic, there are some capabilities I would like to include via extending the classes. Specifically, I want to be able to get an issue's fields by display name, hiding the several queries I must make to the REST API to get a custom field's display name.
In order to properly extend Field, however, I have to either reimplement significant parts of the methods, or make the standard call, and re-instantiate all the returned issues.
Allow us to specify custom types at client instantiation (probably the safest/easiest)
Allow each public method that will return an issue type to have item_type exposed (probably bug-prone and messier)
Expose a GenericJiraClient that allows someone to implement a concrete client with the types passed into the class definition (may be most elegant, but could look funny with multiple concrete types passed in)
1. Example Exposing CustomTypes at Instantiation
This seems a bit friendlier
classCustomIssue(Issue):
defget_field(self, field_name: str, by_display_name: bool=False) ->Any:
ifnothasattr(self.fields, field_name) andby_display_name:
return ...
returnsuper().get_field(field_name)
client=JIRA("server", auth=(), item_types={"issue": CustomIssue}) # Will only replace 'issue' type. All other defaults remain the sameissues=client.search_issues("project=ABC and status=closed")
field=issues[0].get_field("Epic Status", by_display_name=True)
2. Example Exposing item_type for search_issues
This one feels like it would be the most error-prone, since I think you would have to expose something similar for 9 total methods related to fields.
The biggest problem with this is there appears to be 41 different classes inheriting from Resource
Could very easily be the most arduous of the three.
fromtypingimportTypeVarfromjira.resourcesimportIssue, UserT=TypeVar("T", Issue)
U=TypeVar("U", User)
# et ceteraclassGenericJiraClient(Generic[T, U, ...]): ...
classJIRA(GenericJiraClient[Issue, User, ....]): ...
# Or, custom:classMyJiraClient(GenericJiraClient[CustomIssue]): ...
Alternatives
A quicker solution would probably be to just expose methods like these via the JIRA class, and other classes, directly. But I am thinking about extensibility in the field, for users/teams who don't want to wait for a PR to get merged and a new release to happen.
Additional Context
I took a look through the source code, and no other approaches came to mind.
The text was updated successfully, but these errors were encountered:
After thinking on it for a couple days, I think passing custom types as a dict into JIRA would be the easiest to refactor, and minimize required changes.
FWIW, in my projects, I have a dictionary declaring all known (or needed) fields and their what I'd like their equivalent to be, for example:
fields_map= {
'Custom Field 1': 'customfield_10000',
'Custom Field 2': 'customfield_10001'
}
and then I have a layer on top of the library where I initialize my own objects:
classMyCustomIssue:
self.my_var=self.retrieve_field_value('Custom Field 1')
self.my_other_var=self.retrieve_field_value('Custom Field 2')
defretrieve_field_value(self, issue: jira.resources.Issue, field_name: str):
field=getattr(issue, fields_map.get('field_name')) # Get the attribute from the issue objectreturnfield.value# Oversimplified return of said attribute's value
In other cases, I've also end up declaring the various fields with a bit more detail as the JIRA API itself returns the fields in different manner - when retrieved via a search, you'd get the field id (customfield_10000), however if you're retrieving the History tab for example, it will be returned via a label (Custom Field 1), so I personally accounted for that by declaring both of these internally and then working with them depending on what action I'm performing
classJiraField:
self.field_id='customfield_10000'# How is the field returned from the library/APIself.label='Custom Field 1'# How is the field displayed in JIRAself.var_name='my_var'# This is my local classes variable
Just putting here as food for thought,
After thinking on it for a couple days, I think passing custom types as a dict into JIRA would be the easiest to refactor, and minimize required changes.
but I do agree that a simple dictionary should be easiest to maintain.
Problem trying to solve
While this library is fantastic, there are some capabilities I would like to include via extending the classes. Specifically, I want to be able to get an issue's fields by display name, hiding the several queries I must make to the REST API to get a custom field's display name.
In order to properly extend
Field
, however, I have to either reimplement significant parts of the methods, or make the standard call, and re-instantiate all the returned issues.For example:
Possible solution(s)
A couple of thoughts come to mind:
item_type
exposed (probably bug-prone and messier)1. Example Exposing CustomTypes at Instantiation
2. Example Exposing
item_type
forsearch_issues
3. Example with a GeneticJiraClient
Alternatives
A quicker solution would probably be to just expose methods like these via the JIRA class, and other classes, directly. But I am thinking about extensibility in the field, for users/teams who don't want to wait for a PR to get merged and a new release to happen.
Additional Context
I took a look through the source code, and no other approaches came to mind.
The text was updated successfully, but these errors were encountered: