Skip to content

Commit

Permalink
Added new method: append value to a field. Updated docs. (#1379)
Browse files Browse the repository at this point in the history
* Added new method: append value to a field. Updated docs.

* Fix docs
  • Loading branch information
SLRover committed Apr 25, 2024
1 parent 3f33de8 commit d7f8676
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
27 changes: 27 additions & 0 deletions atlassian/jira.py
Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions docs/jira.rst
Expand Up @@ -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
-------------
Expand All @@ -228,8 +228,13 @@ 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):
jira.get_custom_fields(search=None, start=1, limit=50):
# Check issue exists
jira.issue_exists(issue_key)
Expand Down Expand Up @@ -286,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 = {
Expand Down Expand Up @@ -467,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)
Expand Down

0 comments on commit d7f8676

Please sign in to comment.