Skip to content

implemented CommentProperty #1937

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 6 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
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
10 changes: 10 additions & 0 deletions tests/resources/test_comment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from jira.resources import CommentProperty
from tests.conftest import JiraTestCase


Expand Down Expand Up @@ -80,3 +81,12 @@ def test_update_comment_with_notify(self):
comment.update(body="updated! without notification", notify=False)
assert comment.body == "updated! without notification"
comment.delete()

def test_comment_property(self):
comment = self.jira.add_comment(self.issue_1_key, "comment for property test")
comment_prop_data = {'internal': 'true'}
self.jira.add_comment_property(comment, 'sd.public.comment', comment_prop_data)
commentproperty = self.jira.comment_property(comment, 'sd.public.comment')
assert isinstance(commentproperty, CommentProperty)
assert commentproperty.value.internal.lower() == 'true'
comment.delete()