Module ogr.services.github.comments

Expand source code
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import datetime
from typing import Union

from github.IssueComment import IssueComment as _GithubIssueComment
from github.PullRequestComment import PullRequestComment as _GithubPullRequestComment
from github.Reaction import Reaction as _Reaction

from ogr.abstract import Comment, IssueComment, PRComment, Reaction


class GithubReaction(Reaction):
    _raw_reaction: _Reaction

    def __str__(self) -> str:
        return "Github" + super().__str__()

    def delete(self) -> None:
        self._raw_reaction.delete()


class GithubComment(Comment):
    def _from_raw_comment(
        self,
        raw_comment: Union[_GithubIssueComment, _GithubPullRequestComment],
    ) -> None:
        self._raw_comment = raw_comment
        self._id = raw_comment.id
        self._author = raw_comment.user.login
        self._created = raw_comment.created_at

    @property
    def body(self) -> str:
        return self._raw_comment.body

    @body.setter
    def body(self, new_body: str) -> None:
        self._raw_comment.edit(new_body)

    @property
    def edited(self) -> datetime.datetime:
        return self._raw_comment.updated_at

    def get_reactions(self) -> list[Reaction]:
        return [
            GithubReaction(reaction) for reaction in self._raw_comment.get_reactions()
        ]

    def add_reaction(self, reaction: str) -> GithubReaction:
        return GithubReaction(self._raw_comment.create_reaction(reaction))


class GithubIssueComment(GithubComment, IssueComment):
    def __str__(self) -> str:
        return "Github" + super().__str__()


class GithubPRComment(GithubComment, PRComment):
    def __str__(self) -> str:
        return "Github" + super().__str__()

Classes

class GithubComment (raw_comment: Optional[Any] = None, parent: Optional[Any] = None, body: Optional[str] = None, id_: Optional[int] = None, author: Optional[str] = None, created: Optional[datetime.datetime] = None, edited: Optional[datetime.datetime] = None)
Expand source code
class GithubComment(Comment):
    def _from_raw_comment(
        self,
        raw_comment: Union[_GithubIssueComment, _GithubPullRequestComment],
    ) -> None:
        self._raw_comment = raw_comment
        self._id = raw_comment.id
        self._author = raw_comment.user.login
        self._created = raw_comment.created_at

    @property
    def body(self) -> str:
        return self._raw_comment.body

    @body.setter
    def body(self, new_body: str) -> None:
        self._raw_comment.edit(new_body)

    @property
    def edited(self) -> datetime.datetime:
        return self._raw_comment.updated_at

    def get_reactions(self) -> list[Reaction]:
        return [
            GithubReaction(reaction) for reaction in self._raw_comment.get_reactions()
        ]

    def add_reaction(self, reaction: str) -> GithubReaction:
        return GithubReaction(self._raw_comment.create_reaction(reaction))

Ancestors

Subclasses

Inherited members

class GithubIssueComment (raw_comment: Optional[Any] = None, parent: Optional[Any] = None, body: Optional[str] = None, id_: Optional[int] = None, author: Optional[str] = None, created: Optional[datetime.datetime] = None, edited: Optional[datetime.datetime] = None)
Expand source code
class GithubIssueComment(GithubComment, IssueComment):
    def __str__(self) -> str:
        return "Github" + super().__str__()

Ancestors

Inherited members

class GithubPRComment (raw_comment: Optional[Any] = None, parent: Optional[Any] = None, body: Optional[str] = None, id_: Optional[int] = None, author: Optional[str] = None, created: Optional[datetime.datetime] = None, edited: Optional[datetime.datetime] = None)
Expand source code
class GithubPRComment(GithubComment, PRComment):
    def __str__(self) -> str:
        return "Github" + super().__str__()

Ancestors

Inherited members

class GithubReaction (raw_reaction: Any)
Expand source code
class GithubReaction(Reaction):
    _raw_reaction: _Reaction

    def __str__(self) -> str:
        return "Github" + super().__str__()

    def delete(self) -> None:
        self._raw_reaction.delete()

Ancestors

Inherited members