|
| 1 | +############################ Copyrights and license ############################ |
| 2 | +# # |
| 3 | +# Copyright 2024 Enrico Minack <[email protected]> # |
| 4 | +# # |
| 5 | +# This file is part of PyGithub. # |
| 6 | +# http://pygithub.readthedocs.io/ # |
| 7 | +# # |
| 8 | +# PyGithub is free software: you can redistribute it and/or modify it under # |
| 9 | +# the terms of the GNU Lesser General Public License as published by the Free # |
| 10 | +# Software Foundation, either version 3 of the License, or (at your option) # |
| 11 | +# any later version. # |
| 12 | +# # |
| 13 | +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # |
| 14 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # |
| 15 | +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # |
| 16 | +# details. # |
| 17 | +# # |
| 18 | +# You should have received a copy of the GNU Lesser General Public License # |
| 19 | +# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # |
| 20 | +# # |
| 21 | +################################################################################ |
| 22 | + |
| 23 | +from __future__ import annotations |
| 24 | + |
| 25 | +from datetime import datetime |
| 26 | +from typing import Any |
| 27 | + |
| 28 | +import github.GithubObject |
| 29 | +import github.NamedUser |
| 30 | +from github.GithubObject import Attribute, CompletableGithubObject, NotSet |
| 31 | + |
| 32 | + |
| 33 | +class DiscussionBase(CompletableGithubObject): |
| 34 | + """ |
| 35 | + This class represents a the shared attributes between RepositoryDiscussion and TeamDiscussion |
| 36 | + https://docs.github.com/en/graphql/reference/objects#discussion |
| 37 | + https://docs.github.com/en/rest/reference/teams#discussions |
| 38 | + """ |
| 39 | + |
| 40 | + def _initAttributes(self) -> None: |
| 41 | + self._author: Attribute[github.NamedUser.NamedUser | None] = NotSet |
| 42 | + self._body: Attribute[str] = NotSet |
| 43 | + self._body_html: Attribute[str] = NotSet |
| 44 | + self._created_at: Attribute[datetime] = NotSet |
| 45 | + self._last_edited_at: Attribute[datetime] = NotSet |
| 46 | + self._number: Attribute[int] = NotSet |
| 47 | + self._title: Attribute[str] = NotSet |
| 48 | + self._updated_at: Attribute[datetime] = NotSet |
| 49 | + self._url: Attribute[str] = NotSet |
| 50 | + |
| 51 | + def __repr__(self) -> str: |
| 52 | + return self.get__repr__({"number": self._number.value, "title": self._title.value}) |
| 53 | + |
| 54 | + @property |
| 55 | + def author(self) -> github.NamedUser.NamedUser | None: |
| 56 | + self._completeIfNotSet(self._author) |
| 57 | + return self._author.value |
| 58 | + |
| 59 | + @property |
| 60 | + def body(self) -> str: |
| 61 | + self._completeIfNotSet(self._body) |
| 62 | + return self._body.value |
| 63 | + |
| 64 | + @property |
| 65 | + def body_html(self) -> str: |
| 66 | + self._completeIfNotSet(self._body_html) |
| 67 | + return self._body_html.value |
| 68 | + |
| 69 | + @property |
| 70 | + def created_at(self) -> datetime: |
| 71 | + self._completeIfNotSet(self._created_at) |
| 72 | + return self._created_at.value |
| 73 | + |
| 74 | + @property |
| 75 | + def last_edited_at(self) -> datetime: |
| 76 | + self._completeIfNotSet(self._last_edited_at) |
| 77 | + return self._last_edited_at.value |
| 78 | + |
| 79 | + @property |
| 80 | + def number(self) -> int: |
| 81 | + self._completeIfNotSet(self._number) |
| 82 | + return self._number.value |
| 83 | + |
| 84 | + @property |
| 85 | + def title(self) -> str: |
| 86 | + self._completeIfNotSet(self._title) |
| 87 | + return self._title.value |
| 88 | + |
| 89 | + @property |
| 90 | + def updated_at(self) -> datetime: |
| 91 | + self._completeIfNotSet(self._updated_at) |
| 92 | + return self._updated_at.value |
| 93 | + |
| 94 | + @property |
| 95 | + def url(self) -> str: |
| 96 | + self._completeIfNotSet(self._url) |
| 97 | + return self._url.value |
| 98 | + |
| 99 | + def _useAttributes(self, attributes: dict[str, Any]) -> None: |
| 100 | + if "author" in attributes: # pragma no branch |
| 101 | + self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) |
| 102 | + if "body" in attributes: # pragma no branch |
| 103 | + self._body = self._makeStringAttribute(attributes["body"]) |
| 104 | + if "body_html" in attributes: # pragma no branch |
| 105 | + self._body_html = self._makeStringAttribute(attributes["body_html"]) |
| 106 | + if "created_at" in attributes: # pragma no branch |
| 107 | + self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) |
| 108 | + if "last_edited_at" in attributes: # pragma no branch |
| 109 | + self._last_edited_at = self._makeDatetimeAttribute(attributes["last_edited_at"]) |
| 110 | + if "number" in attributes: # pragma no branch |
| 111 | + self._number = self._makeIntAttribute(attributes["number"]) |
| 112 | + if "title" in attributes: |
| 113 | + self._title = self._makeStringAttribute(attributes["title"]) |
| 114 | + if "updated_at" in attributes: # pragma no branch |
| 115 | + self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) |
| 116 | + if "url" in attributes: # pragma no branch |
| 117 | + self._url = self._makeStringAttribute(attributes["url"]) |
0 commit comments