CommitComment (#2634)

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
Trim21
2023-08-09 13:20:01 +02:00
committed by GitHub
co-authored by Enrico Minack
parent aedfa0b912
commit d02ef2231f
2 changed files with 40 additions and 110 deletions
+40 -71
View File
@@ -30,123 +30,107 @@
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from __future__ import annotations
from typing import Any, Dict
from datetime import datetime
from typing import TYPE_CHECKING, Any
import github.GithubObject
import github.NamedUser
from github import Consts
from github.GithubObject import Attribute, CompletableGithubObject, NotSet
from github.PaginatedList import PaginatedList
from . import Consts
if TYPE_CHECKING:
from github.Reaction import Reaction
class CommitComment(github.GithubObject.CompletableGithubObject):
class CommitComment(CompletableGithubObject):
"""
This class represents CommitComments. The reference can be found here https://docs.github.com/en/rest/reference/repos#comments
"""
def _initAttributes(self) -> None:
self._body: Attribute[str] = NotSet
self._commit_id: Attribute[str] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._html_url: Attribute[str] = NotSet
self._id: Attribute[int] = NotSet
self._line: Attribute[int] = NotSet
self._path: Attribute[str] = NotSet
self._position: Attribute[int] = NotSet
self._updated_at: Attribute[datetime] = NotSet
self._url: Attribute[str] = NotSet
self._user: Attribute[github.NamedUser.NamedUser] = NotSet
def __repr__(self) -> str:
return self.get__repr__({"id": self._id.value, "user": self.user})
@property
def body(self):
"""
:type: string
"""
def body(self) -> str:
self._completeIfNotSet(self._body)
return self._body.value
@property
def commit_id(self):
"""
:type: string
"""
def commit_id(self) -> str:
self._completeIfNotSet(self._commit_id)
return self._commit_id.value
@property
def created_at(self):
"""
:type: datetime.datetime
"""
def created_at(self) -> datetime:
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
def html_url(self):
"""
:type: string
"""
def html_url(self) -> str:
self._completeIfNotSet(self._html_url)
return self._html_url.value
@property
def id(self):
"""
:type: integer
"""
def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value
@property
def line(self):
"""
:type: integer
"""
def line(self) -> int:
self._completeIfNotSet(self._line)
return self._line.value
@property
def path(self):
"""
:type: string
"""
def path(self) -> str:
self._completeIfNotSet(self._path)
return self._path.value
@property
def position(self):
"""
:type: integer
"""
def position(self) -> int:
self._completeIfNotSet(self._position)
return self._position.value
@property
def updated_at(self):
"""
:type: datetime.datetime
"""
def updated_at(self) -> datetime:
self._completeIfNotSet(self._updated_at)
return self._updated_at.value
@property
def url(self):
"""
:type: string
"""
def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value
@property
def user(self):
"""
:type: :class:`github.NamedUser.NamedUser`
"""
def user(self) -> github.NamedUser.NamedUser:
self._completeIfNotSet(self._user)
return self._user.value
def delete(self):
def delete(self) -> None:
"""
:calls: `DELETE /repos/{owner}/{repo}/comments/{id} <https://docs.github.com/en/rest/reference/repos#comments>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
def edit(self, body):
def edit(self, body: str) -> None:
"""
:calls: `PATCH /repos/{owner}/{repo}/comments/{id} <https://docs.github.com/en/rest/reference/repos#comments>`_
:param body: string
:rtype: None
"""
assert isinstance(body, str), body
post_parameters = {
@@ -155,13 +139,13 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
self._useAttributes(data)
def get_reactions(self):
def get_reactions(self) -> PaginatedList[Reaction]:
"""
:calls: `GET /repos/{owner}/{repo}/comments/{id}/reactions
<https://docs.github.com/en/rest/reference/reactions#list-reactions-for-a-commit-comment>`_
:return: :class: :class:`github.PaginatedList.PaginatedList` of :class:`github.Reaction.Reaction`
"""
return github.PaginatedList.PaginatedList(
return PaginatedList(
github.Reaction.Reaction,
self._requester,
f"{self.url}/reactions",
@@ -169,12 +153,10 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
headers={"Accept": Consts.mediaTypeReactionsPreview},
)
def create_reaction(self, reaction_type):
def create_reaction(self, reaction_type: str) -> Reaction:
"""
:calls: `POST /repos/{owner}/{repo}/comments/{id}/reactions
<https://docs.github.com/en/rest/reference/reactions#create-reaction-for-a-commit-comment>`_
:param reaction_type: string
:rtype: :class:`github.Reaction.Reaction`
"""
assert isinstance(reaction_type, str), reaction_type
post_parameters = {
@@ -188,7 +170,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
)
return github.Reaction.Reaction(self._requester, headers, data, completed=True)
def delete_reaction(self, reaction_id):
def delete_reaction(self, reaction_id: int) -> bool:
"""
:calls: `DELETE /repos/{owner}/{repo}/comments/{comment_id}/reactions/{reaction_id}
<https://docs.github.com/en/rest/reference/reactions#delete-a-commit-comment-reaction>`_
@@ -203,20 +185,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject):
)
return status == 204
def _initAttributes(self) -> None:
self._body = github.GithubObject.NotSet
self._commit_id = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._html_url = github.GithubObject.NotSet
self._id = github.GithubObject.NotSet
self._line = github.GithubObject.NotSet
self._path = github.GithubObject.NotSet
self._position = github.GithubObject.NotSet
self._updated_at = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
self._user = github.GithubObject.NotSet
def _useAttributes(self, attributes: Dict[str, Any]) -> None:
def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "commit_id" in attributes: # pragma no branch