Skip to content

Commit

Permalink
add notify param to worklog and attachment operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Aug 20, 2023
1 parent da00ec0 commit 4aa5a22
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 10 additions & 2 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,17 +1053,21 @@ def prepare(
)
return jira_attachment

def delete_attachment(self, id: str) -> Response:
def delete_attachment(self, id: str, notify: bool | None = None) -> Response:
"""Delete attachment by id.
Args:
id (str): ID of the attachment to delete
notify (Optional[bool]): Whether users watching the issue are notified by email. Sets API `notifyUsers` param.
Returns:
Response
"""
params = {}
if notify is not None:
params["notifyUsers"] = "true" if notify else "false"
url = self._get_url("attachment/" + str(id))
return self._session.delete(url)
return self._session.delete(url, params=params)

# Components

Expand Down Expand Up @@ -2405,6 +2409,7 @@ def add_worklog(
comment: (str | None) = None,
started: (datetime.datetime | None) = None,
user: (str | None) = None,
notify: bool | None = None,
) -> Worklog:
"""Add a new worklog entry on an issue and return a Resource for it.
Expand All @@ -2419,6 +2424,7 @@ def add_worklog(
comment (Optional[str]): optional worklog comment
started (Optional[datetime.datetime]): Moment when the work is logged, if not specified will default to now
user (Optional[str]): the user ID or name to use for this worklog
notify (Optional[bool]): Whether users watching the issue are notified by email. Sets API `notifyUsers` param.
Returns:
Worklog
Expand All @@ -2430,6 +2436,8 @@ def add_worklog(
params["newEstimate"] = newEstimate
if reduceBy is not None:
params["reduceBy"] = reduceBy
if notify is not None:
params["notifyUsers"] = notify

data: dict[str, Any] = {}
if timeSpent is not None:
Expand Down
16 changes: 13 additions & 3 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,23 @@ def update(
time.sleep(self._options["delay_reload"])
self._load(self.self)

def delete(self, params: dict[str, Any] | None = None) -> Response | None:
def delete(
self, params: dict[str, Any] | None = None, notify: bool | None = None
) -> Response | None:
"""Delete this resource from the server, passing the specified query parameters.
If this resource doesn't support ``DELETE``, a :py:exc:`.JIRAError` will be raised; subclasses that specialize this method will
only raise errors in case of user error.
Args:
params: Parameters for the delete request.
notify: if specified, sets `notifyUsers` parameter.
Returns:
Optional[Response]: Returns None if async
"""
if notify is not None:
params["notifyUsers"] = "true" if notify else "false"
if self._options["async"]:
# FIXME: mypy doesn't think this should work
if not hasattr(self._session, "_async_jobs"):
Expand Down Expand Up @@ -954,7 +959,11 @@ def __init__(
self.raw: dict[str, Any] = cast(Dict[str, Any], self.raw)

def delete( # type: ignore[override]
self, adjustEstimate: str | None = None, newEstimate=None, increaseBy=None
self,
adjustEstimate: str | None = None,
newEstimate=None,
increaseBy=None,
notify: bool | None = None,
):
"""Delete this worklog entry from its associated issue.
Expand All @@ -964,6 +973,7 @@ def delete( # type: ignore[override]
``leave`` leaves the estimate unchanged by this deletion.
newEstimate: combined with ``adjustEstimate=new``, set the estimate to this value
increaseBy: combined with ``adjustEstimate=manual``, increase the remaining estimate by this amount
notify (Optional[bool]): Whether users watching the issue are notified by email. Sets API `notifyUsers` param.
"""
params = {}
if adjustEstimate is not None:
Expand All @@ -973,7 +983,7 @@ def delete( # type: ignore[override]
if increaseBy is not None:
params["increaseBy"] = increaseBy

super().delete(params)
super().delete(params, notify=notify)


class IssueProperty(Resource):
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/test_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_1_add_remove_attachment_using_filestream(self):
new_attachment.size, os.path.getsize(TEST_ATTACH_PATH), msg=msg
)
# JIRA returns a HTTP 204 upon successful deletion
self.assertEqual(attachment.delete().status_code, 204)
self.assertEqual(attachment.delete(notify=False).status_code, 204)

def test_attach_with_no_filename(self):
issue = self.jira.issue(self.issue_1)
Expand Down
4 changes: 4 additions & 0 deletions tests/resources/test_worklog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_add_worklog(self):
self.assertEqual(len(self.jira.worklogs(self.issue_2)), worklog_count + 1)
worklog.delete()

def test_add_worklog_with_notify_false(self):
worklog = self.jira.add_worklog(self.issue_2, "2h", notify=False)
worklog.delete(notify=False)

def test_add_worklog_with_issue_obj(self):
issue = self.jira.issue(self.issue_2)
worklog_count = len(self.jira.worklogs(issue))
Expand Down

0 comments on commit 4aa5a22

Please sign in to comment.