Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new method: append value to a field. Updated docs. #1379

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading