Skip to content

Add issue.remove_field_value() #1834

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,17 +893,28 @@ def get_field(self, field_name: str) -> Any:
else:
return getattr(self.fields, field_name)

def add_field_value(self, field: str, value: str):
def add_field_value(self, field: str, value: Any):
"""Add a value to a field that supports multiple values, without resetting the existing values.

This should work with: labels, multiple checkbox lists, multiple select

Args:
field (str): The field name
value (str): The field's value
value (Any): The field's value
"""
super().update(fields={"update": {field: [{"add": value}]}})

def remove_field_value(self, field: str, value: Any):
"""Remove a value from a field that supports multiple values, without resetting the existing values.

This should work with: labels, multiple checkbox lists, multiple select

Args:
field (str): The field name
value (Any): The field's value
"""
super().update(fields={"update": {field: [{"remove": value}]}})

def delete(self, deleteSubtasks=False):
"""Delete this issue from the server.

Expand Down
22 changes: 22 additions & 0 deletions tests/resources/test_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,28 @@ def test_update_with_fielddict(self):
self.assertEqual(issue.fields.priority.name, "High")
issue.delete()

def test_add_remove_field_values(self):
issue = self.jira.create_issue(
summary="Test issue for updating labels",
project=self.project_b,
description="Label testing",
issuetype=self.test_manager.CI_JIRA_ISSUE,
)

labelarray = ["testLabel1"]
fields = {"labels": labelarray}

issue.update(fields=fields)
self.assertEqual(issue.fields.labels, ["testLabel1"])

issue.add_field_value("labels", "testLabel2")
self.assertEqual(issue.fields.labels, ["testLabel1", "testLabel2"])

issue.remove_field_value("labels", "testLabel1")
self.assertEqual(issue.fields.labels, ["testLabel2"])

issue.delete()

def test_update_with_label(self):
issue = self.jira.create_issue(
summary="Test issue for updating labels",
Expand Down