Skip to content

Commit 327737f

Browse files
authored
redo custom field option commit with latest sync (#1620)
1 parent 5728cfa commit 327737f

File tree

2 files changed

+127
-3
lines changed

2 files changed

+127
-3
lines changed

atlassian/jira.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,60 @@ def get_custom_field_option(self, option_id: T_id) -> T_resp_json:
775775
url = f"{base_url}/{option_id}"
776776
return self.get(url)
777777

778+
def get_custom_field_options(
779+
self,
780+
field_id: T_id,
781+
project_id: T_id,
782+
issue_type_id: Union[T_id, list[str], None] = None,
783+
query: Optional[str] = None,
784+
page: Optional[int] = None,
785+
limit: Optional[int] = None,
786+
sort: Optional[bool] = None,
787+
use_all_contexts: Optional[bool] = None,
788+
) -> T_resp_json:
789+
"""
790+
Get list of all options available for a custom field in a specified project.
791+
Numeric field ID and numeric project ID must be used.
792+
793+
This is Experimental API available to Jira data Center.
794+
At the time of testing, providing multiple project IDs results in 404 response.
795+
796+
Reference: https://developer.atlassian.com/server/jira/platform/rest/v11003/api-group-customfields/#api-api-2-customfields-customfieldid-options-get
797+
798+
:param field_id: str - The ID of the custom field.
799+
:param project_id: str - The project ID in a context.
800+
:param issue_type_id: str, Optional - A list of issue type IDs in a context.
801+
:param query: str, Optional - A string used to filter options.
802+
:param page: int, Optional - The page of options to return, starting from 1.
803+
:param limit: int, Optional - The maximum number of results to return. If empty, return all results.
804+
:param sort: bool, Optional - Flag to sort options by their names.
805+
:param use_all_contexts: bool, Optional - Flag to fetch all options regardless of context, project IDs, or issue type IDs.
806+
"""
807+
url = self.resource_url(
808+
f"customFields/{field_id}/options",
809+
api_version=2,
810+
)
811+
params: dict = {}
812+
if project_id:
813+
if isinstance(project_id, (list, tuple, set)):
814+
project_id = ",".join(project_id)
815+
params["projectIds"] = project_id
816+
if issue_type_id:
817+
if isinstance(issue_type_id, (list, tuple, set)):
818+
issue_type_id = ",".join(issue_type_id)
819+
params["issueTypeIds"] = issue_type_id
820+
if query:
821+
params["query"] = query
822+
if page is not None:
823+
params["page"] = page
824+
if limit is not None:
825+
params["maxResults"] = limit
826+
if sort is not None:
827+
params["sortByOptionName"] = sort
828+
if use_all_contexts is not None:
829+
params["useAllContexts"] = use_all_contexts
830+
return self.get(url, params=params)
831+
778832
def get_custom_fields(self, search: Optional[str] = None, start: int = 1, limit: int = 50) -> T_resp_json:
779833
"""
780834
Get custom fields. Evaluated on 7.12
@@ -3972,6 +4026,60 @@ def get_priority_by_id(self, priority_id: T_id) -> T_resp_json:
39724026
url = f"{base_url}/{priority_id}"
39734027
return self.get(url)
39744028

4029+
def get_autocomplete_data(self) -> T_resp_json:
4030+
"""
4031+
Returns full information about visible fields that can be autocompleted in JQL.
4032+
4033+
Available in Jira Data Center, Jira Cloud v2, Jira Cloud v3.
4034+
4035+
Reference: https://developer.atlassian.com/server/jira/platform/rest/v11003/api-group-jql/#api-api-2-jql-autocompletedata-get
4036+
https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-jql/#api-rest-api-2-jql-autocompletedata-get
4037+
:return:
4038+
"""
4039+
url = self.resource_url("jql/autocompletedata")
4040+
return self.get(url)
4041+
4042+
def get_autocomplete_suggestion(
4043+
self,
4044+
field_name: Optional[str] = None,
4045+
field_value: Optional[str] = None,
4046+
predicate_name: Optional[str] = None,
4047+
predicate_value: Optional[str] = None,
4048+
) -> T_resp_json:
4049+
"""
4050+
Returns auto complete suggestions for JQL search.
4051+
4052+
Suggestions can be obtained by providing:
4053+
4054+
`fieldName` to get a list of all values for the field.
4055+
`fieldName` and `fieldValue` to get a list of values containing the text in `fieldValue`.
4056+
`fieldName` and `predicateName` to get a list of all predicate values for the field.
4057+
`fieldName`, `predicateName`, and `predicateValue` to get a list of predicate values containing the text in `predicateValue`.
4058+
4059+
Although auto complete suggestion can be used to retrieve possible option for a field,
4060+
it may be more appropriate to use `get_custom_field_options()` method to get project-specific options for a field.
4061+
4062+
Reference: https://developer.atlassian.com/server/jira/platform/rest/v11003/api-group-jql/#api-api-2-jql-autocompletedata-suggestions-get
4063+
https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-jql/#api-rest-api-2-jql-autocompletedata-suggestions-get
4064+
4065+
:param field_name: str, Optional - The field name for which the suggestions are generated.
4066+
:param field_value: str, Optional - The portion of the field value that has already been provided by the user.
4067+
:param predicate_name: str, Optional - The predicate for which the suggestions are generated. Suggestions are generated only for: "by", "from" and "to".
4068+
:param predicate_value: str, Optional - The portion of the predicate value that has already been provided by the user.
4069+
:return:
4070+
"""
4071+
url = self.resource_url("jql/autocompletedata/suggestions")
4072+
params: dict = {}
4073+
if field_name:
4074+
params["fieldName"] = field_name
4075+
if field_value:
4076+
params["fieldValue"] = field_value
4077+
if predicate_name:
4078+
params["predicateName"] = predicate_name
4079+
if predicate_value:
4080+
params["predicateValue"] = predicate_value
4081+
return self.get(url, params=params)
4082+
39754083
"""
39764084
Workflow
39774085
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/workflow

docs/jira.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ Manage projects
229229
# Using " " string (space) for username gives All the active users who have browse permission for a project
230230
jira.get_users_with_browse_permission_to_a_project(username, issue_key=None, project_key=None, start=0, limit=100)
231231
232+
# Get existing custom fields or find by filter
233+
jira.get_custom_fields(search=None, start=1, limit=50):
234+
235+
# Returns a full representation of a Custom Field Option that has the given id.
236+
option_id = 10001
237+
jira.get_custom_field_option(option_id)
238+
239+
# Returns full list of Custom Field Options in a specified project.
240+
field_id = 10000
241+
project_id = 1234
242+
jira.get_custom_field_options(field_id, project_id, issue_type_id=None)
243+
232244
Manage issues
233245
-------------
234246

@@ -252,9 +264,6 @@ Manage issues
252264
value = {"name": "username"}
253265
jira.issue_field_value_append(issue_id_or_key, field, value, notify_users=True)
254266
255-
# Get existing custom fields or find by filter
256-
jira.get_custom_fields(search=None, start=1, limit=50):
257-
258267
# Check issue exists
259268
jira.issue_exists(issue_key)
260269
@@ -439,6 +448,13 @@ Manage issues
439448
# :return: list of dictionaries containing the tree structure. Dictionary element contains a key (parent issue) and value (child issue).
440449
jira.get_issue_tree_recursive(issue_key, tree=[], depth=0)
441450
451+
# Returns full information about visible fields that can be autocompleted in JQL.
452+
jira.get_autocomplete_data()
453+
454+
# Returns auto complete suggestions for JQL search.
455+
field_name = "Custom Field"
456+
jira.get_autocomplete_suggestion(field_name, field_value=None, predicate_name=None, predicate_value=None)
457+
442458
Epic Issues
443459
-------------
444460

0 commit comments

Comments
 (0)