Skip to content

Commit

Permalink
Merge pull request #748 from FrNecas/comment-body
Browse files Browse the repository at this point in the history
Deprecate CommitComment.comment in favour of body

Related to packit/packit-service#1716
RELEASE NOTES BEGIN
CommitComment.comment has been deprecated in favour of CommitComment.body to make the naming consistent across objects.
RELEASE NOTES END

Reviewed-by: Laura Barcziová <None>
Reviewed-by: None <None>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 24, 2022
2 parents 565235b + 164a803 commit 3e107c9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
20 changes: 16 additions & 4 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OgrNetworkError,
)
from ogr.parsing import parse_git_repo
from ogr.deprecation import deprecate_and_set_removal

try:
from functools import cached_property as _cached_property
Expand Down Expand Up @@ -1028,17 +1029,28 @@ class CommitComment(OgrAbstractClass):
"""
Attributes:
sha (str): Hash of the related commit.
comment (str): Body of the comment.
body (str): Body of the comment.
author (str): Login of the author.
"""

def __init__(self, sha: str, comment: str, author: str) -> None:
def __init__(self, sha: str, body: str, author: str) -> None:
self.sha = sha
self.comment = comment
self.body = body
self.author = author

@property # type: ignore
@deprecate_and_set_removal(
since="0.41.0",
remove_in="0.46.0 (or 1.0.0 if it comes sooner)",
message="Use body",
)
def comment(self) -> str:
return self.body

def __str__(self) -> str:
return f"CommitComment(commit={self.sha}, author={self.author}, comment={self.comment})"
return (
f"CommitComment(commit={self.sha}, author={self.author}, body={self.body})"
)


class GitTag(OgrAbstractClass):
Expand Down
20 changes: 0 additions & 20 deletions ogr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import github
import gitlab

from ogr.deprecation import deprecate_and_set_removal


class OgrException(Exception):
"""Something went wrong during our execution."""
Expand Down Expand Up @@ -50,15 +48,6 @@ def response_code(self):
class GithubAPIException(APIException):
"""Exception related to Github API."""

@property # type: ignore
@deprecate_and_set_removal(
since="0.30.0",
remove_in="0.35.0 (or 1.0.0 if it comes sooner)",
message="Use __cause__",
)
def github_error(self):
return self.__cause__

@property
def response_code(self):
if self.__cause__ is None or not isinstance(
Expand All @@ -71,15 +60,6 @@ def response_code(self):
class GitlabAPIException(APIException):
"""Exception related to Gitlab API."""

@property # type: ignore
@deprecate_and_set_removal(
since="0.30.0",
remove_in="0.35.0 (or 1.0.0 if it comes sooner)",
message="Use __cause__",
)
def gitlab_error(self):
return self.__cause__

@property
def response_code(self):
if self.__cause__ is None or not isinstance(self.__cause__, gitlab.GitlabError):
Expand Down
2 changes: 1 addition & 1 deletion ogr/read_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def fork_create(
def commit_comment(
cls, original_object: Any, commit: str, body: str
) -> "CommitComment":
return CommitComment(sha=commit, comment=body, author=cls.author)
return CommitComment(sha=commit, body=body, author=cls.author)

@classmethod
def set_commit_status(
Expand Down
2 changes: 1 addition & 1 deletion ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _commit_comment_from_github_object(
raw_commit_coment: GithubCommitComment,
) -> CommitComment:
return CommitComment(
comment=raw_commit_coment.body,
body=raw_commit_coment.body,
author=raw_commit_coment.user.login,
sha=raw_commit_coment.commit_id,
)
Expand Down
2 changes: 1 addition & 1 deletion ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def commit_comment(
@staticmethod
def _commit_comment_from_gitlab_object(raw_comment, commit) -> CommitComment:
return CommitComment(
sha=commit, comment=raw_comment.note, author=raw_comment.author["username"]
sha=commit, body=raw_comment.note, author=raw_comment.author["username"]
)

def get_commit_comments(self, commit: str) -> List[CommitComment]:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/github/test_generic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_commit_comment(self):
row=6,
)
assert comment.sha == "95069d7bedb6ae02def3fccce22169b412d08eac"
assert comment.comment == "Testing commit comment"
assert comment.body == "Testing commit comment"
assert comment.author == self.service.user.get_username()

def test_get_commit_comments(self):
Expand All @@ -240,7 +240,7 @@ def test_get_commit_comments(self):
)
assert len(comments)
assert comments[0].sha == "95069d7bedb6ae02def3fccce22169b412d08eac"
assert comments[0].comment == "Testing commit comment"
assert comments[0].body == "Testing commit comment"

def test_get_web_url(self):
url = self.ogr_project.get_web_url()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/gitlab/test_generic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def test_commit_comment(self):
row=3,
)
assert comment.author == self.service.user.get_username()
assert comment.comment == "Comment to line 3"
assert comment.body == "Comment to line 3"

def test_get_commit_comments(self):
comments = self.project.get_commit_comments(
"11b37d913374b14f8519d16c2a2cca3ebc14ac64"
)
assert len(comments)
assert comments[0].sha == "11b37d913374b14f8519d16c2a2cca3ebc14ac64"
assert comments[0].comment == "Comment to line 3"
assert comments[0].body == "Comment to line 3"

def test_get_web_url(self):
url = self.project.get_web_url()
Expand Down

0 comments on commit 3e107c9

Please sign in to comment.