Module ogr.services.pagure.comments

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

import datetime
from typing import Any, Optional

from ogr.abstract import Comment, IssueComment, PRComment
from ogr.exceptions import OperationNotSupported


class PagureComment(Comment):
    def _from_raw_comment(self, raw_comment: dict[str, Any]) -> None:
        self._body = raw_comment["comment"]
        self._id = raw_comment["id"]
        self._author = raw_comment["user"]["name"]
        self._created = self.__datetime_from_timestamp(raw_comment["date_created"])
        self._edited = self.__datetime_from_timestamp(raw_comment["edited_on"])

    @staticmethod
    def __datetime_from_timestamp(
        timestamp: Optional[str],
    ) -> Optional[datetime.datetime]:
        return datetime.datetime.fromtimestamp(int(timestamp)) if timestamp else None

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

    @body.setter
    def body(self, new_body: str) -> None:
        raise OperationNotSupported()


class PagureIssueComment(PagureComment, IssueComment):
    def __str__(self) -> str:
        return "Pagure" + super().__str__()


class PagurePRComment(PagureComment, PRComment):
    def __str__(self) -> str:
        return "Pagure" + super().__str__()

Classes

class PagureComment (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 PagureComment(Comment):
    def _from_raw_comment(self, raw_comment: dict[str, Any]) -> None:
        self._body = raw_comment["comment"]
        self._id = raw_comment["id"]
        self._author = raw_comment["user"]["name"]
        self._created = self.__datetime_from_timestamp(raw_comment["date_created"])
        self._edited = self.__datetime_from_timestamp(raw_comment["edited_on"])

    @staticmethod
    def __datetime_from_timestamp(
        timestamp: Optional[str],
    ) -> Optional[datetime.datetime]:
        return datetime.datetime.fromtimestamp(int(timestamp)) if timestamp else None

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

    @body.setter
    def body(self, new_body: str) -> None:
        raise OperationNotSupported()

Ancestors

Subclasses

Inherited members

class PagureIssueComment (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 PagureIssueComment(PagureComment, IssueComment):
    def __str__(self) -> str:
        return "Pagure" + super().__str__()

Ancestors

Inherited members

class PagurePRComment (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 PagurePRComment(PagureComment, PRComment):
    def __str__(self) -> str:
        return "Pagure" + super().__str__()

Ancestors

Inherited members