Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
*.swp
*.bak
*.egg
*.egg-info/
Expand Down
43 changes: 43 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
Attachment,
Board,
Comment,
CommentProperty,
Component,
Customer,
CustomFieldOption,
Expand Down Expand Up @@ -2353,6 +2354,48 @@ def add_comment(

return Comment(self._options, self._session, raw=json_loads(r))

# Comment properties

@translate_resource_args
def comment_properties(self, comment: str) -> list[CommentProperty]:
"""Get a list of comment property Resource from the server for an issue.

Args:
comment (str): ID of the comment to get properties from

Returns:
List[CommentProperty]
"""
r_json = self._get_json(f"comment/{comment}/properties")
properties = [self.comment_property(comment, key["key"]) for key in r_json["keys"]]
return properties

@translate_resource_args
def comment_property(self, comment: str, key: str) -> CommentProperty:
"""Get a specific comment property Resource from the server.

Args:
comment (str): ID of the comment to get the property from
key (str): Key of the property to get
Returns:
CommentProperty
"""
return self._find_for_resource(CommentProperty, (comment, key))

@translate_resource_args
def add_comment_property(self, comment: str, key: str, data) -> Response:
"""Add or update a specific comment property Resource.

Args:
comment (str): ID of the comment to set the property to
key (str): Key of the property to set
data: The data to set for the property
Returns:
Response
"""
url = self._get_url(f"comment/{comment}/properties/{key}")
return self._session.put(url, data=json.dumps(data))

# non-resource
@translate_resource_args
def editmeta(self, issue: str | int):
Expand Down
26 changes: 26 additions & 0 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AnyLike:
"Resource",
"Issue",
"Comment",
"CommentProperty",
"Project",
"Attachment",
"Component",
Expand Down Expand Up @@ -971,6 +972,30 @@ def __init__(
self.raw: dict[str, Any] = cast(dict[str, Any], self.raw)


class CommentProperty(Resource):
"""Custom data against an comment."""

def __init__(
self,
options: dict[str, str],
session: ResilientSession,
raw: dict[str, Any] | None = None,
):
Resource.__init__(self, "comment/{0}/properties/{1}", options, session)
if raw:
self._parse_raw(raw)
self.raw: dict[str, Any] = cast(dict[str, Any], self.raw)

def _find_by_url(
self,
url: str,
params: dict[str, str] | None = None,
):
super()._find_by_url(url, params)
# An CommentProperty never returns "self" identifier, set it
self.self = url


class RemoteLink(Resource):
"""A link to a remote application from an issue."""

Expand Down Expand Up @@ -1675,6 +1700,7 @@ def dict2resource(
r"filter/[^/]$": Filter,
r"issue/[^/]+$": Issue,
r"issue/[^/]+/comment/[^/]+$": Comment,
r"comment/[^/]+/properties/[^/]+$": CommentProperty,
r"issue/[^/]+/pinned-comments$": PinnedComment,
r"issue/[^/]+/votes$": Votes,
r"issue/[^/]+/watchers$": Watchers,
Expand Down
Loading