From 0bcd233a598758ac64e75fd67fa1675f528dd1a6 Mon Sep 17 00:00:00 2001 From: Ilya Sapunov Date: Tue, 23 Apr 2024 18:39:24 +0300 Subject: [PATCH 1/2] Added new method: append value to a field. Updated docs. --- atlassian/jira.py | 27 +++++++++++++++++++++++++++ docs/jira.rst | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/atlassian/jira.py b/atlassian/jira.py index bd24798a6..a2556c022 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -1336,6 +1336,33 @@ def bulk_update_issue_field(self, key_list, fields="*all"): return False return True + def issue_field_value_append(self, issue_id_or_key, field, value, notify_users=True): + """ + Add value to a multiple value field + + :param issue_id_or_key: str Issue id or issue key + :param field: str Field key ("customfield_10000") + :param value: str A value which need to append (use python value types) + :param notify_users: bool OPTIONAL if True, use project's default notification scheme to notify users via email. + if False, do not send any email notifications. (only works with admin privilege) + """ + base_url = self.resource_url("issue") + params = {"notifyUsers": True if notify_users else False} + current_value = self.issue_field_value(key=issue_id_or_key, field=field) + + if current_value: + new_value = current_value + [value] + else: + new_value = [value] + + fields = {'{}'.format(field): new_value} + + return self.put( + "{base_url}/{key}".format(base_url=base_url, key=issue_id_or_key), + data={"fields": fields}, + params=params, + ) + def get_issue_labels(self, issue_key): """ Get issue labels. diff --git a/docs/jira.rst b/docs/jira.rst index 436993543..ee9227b9e 100644 --- a/docs/jira.rst +++ b/docs/jira.rst @@ -228,6 +228,11 @@ Manage issues fields = {'summary': 'New summary'} jira.update_issue_field(key, fields, notify_users=True) + # Append value to issue field + field = 'customfield_10000' + value = {'name': 'username'} + jira.issue_field_value_append(issue_id_or_key, field, value, notify_users=True) + # Get existing custom fields or find by filter jira.get_custom_fields(self, search=None, start=1, limit=50): From 8ccf9649aa20943d59d45248fc39d06ed6ab4cd9 Mon Sep 17 00:00:00 2001 From: Ilya Sapunov Date: Wed, 24 Apr 2024 16:18:31 +0300 Subject: [PATCH 2/2] Fix docs --- docs/jira.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/jira.rst b/docs/jira.rst index ee9227b9e..4038cb907 100644 --- a/docs/jira.rst +++ b/docs/jira.rst @@ -211,7 +211,7 @@ Manage projects # Returns a list of active users who have browse permission for a project that matches the search string for username. # Using " " string (space) for username gives All the active users who have browse permission for a project - jira.get_users_with_browse_permission_to_a_project(self, username, issue_key=None, project_key=None, start=0, limit=100) + jira.get_users_with_browse_permission_to_a_project(username, issue_key=None, project_key=None, start=0, limit=100) Manage issues ------------- @@ -234,7 +234,7 @@ Manage issues jira.issue_field_value_append(issue_id_or_key, field, value, notify_users=True) # Get existing custom fields or find by filter - jira.get_custom_fields(self, search=None, start=1, limit=50): + jira.get_custom_fields(search=None, start=1, limit=50): # Check issue exists jira.issue_exists(issue_key) @@ -291,7 +291,7 @@ Manage issues jira.issue_createmeta_issuetypes(project, start=None, limit=None) # Get create field metadata for a project and issue type id - jira.issue_createmeta_fieldtypes(self, project, issue_type_id, start=None, limit=None) + jira.issue_createmeta_fieldtypes(project, issue_type_id, start=None, limit=None) # Create Issue Link data = { @@ -472,7 +472,7 @@ Manage Sprints jira.get_all_issues_for_sprint_in_board(board_id, state=None, start=0, limit=50) # Get all versions for sprint in board - jira.get_all_versions_from_board(self, board_id, released="true", start=0, limit=50) + jira.get_all_versions_from_board(board_id, released="true", start=0, limit=50) # Create sprint jira.jira.create_sprint(sprint_name, origin_board_id, start_datetime, end_datetime, goal)