From 7cf3dfc18e0442ab181ff8fa8d2080670f0ba7ac Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 31 Jan 2023 00:44:16 +0100 Subject: [PATCH] Continue the PR #1899 (#2386) * A property to access the `assets` field of release (#1898) ... in order to avoid extra requests. * Remove comment to comply the review * Add tests for GitRelease.assets --------- Co-authored-by: green-green-avk <45503261+green-green-avk@users.noreply.github.com> --- github/GitRelease.py | 13 +++++++++++++ github/GitRelease.pyi | 2 ++ tests/GitRelease.py | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/github/GitRelease.py b/github/GitRelease.py index 4268fd16..56f56ea2 100644 --- a/github/GitRelease.py +++ b/github/GitRelease.py @@ -170,6 +170,14 @@ class GitRelease(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._zipball_url) return self._zipball_url.value + @property + def assets(self): + """ + :type: list of :class:`github.GitReleaseAsset.GitReleaseAsset` + """ + self._completeIfNotSet(self._assets) + return self._assets.value + def delete_release(self): """ :calls: `DELETE /repos/{owner}/{repo}/releases/{release_id} `_ @@ -333,6 +341,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): self._published_at = github.GithubObject.NotSet self._tarball_url = github.GithubObject.NotSet self._zipball_url = github.GithubObject.NotSet + self._assets = github.GithubObject.NotSet def _useAttributes(self, attributes): if "id" in attributes: @@ -369,3 +378,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): self._tarball_url = self._makeStringAttribute(attributes["tarball_url"]) if "zipball_url" in attributes: self._zipball_url = self._makeStringAttribute(attributes["zipball_url"]) + if "assets" in attributes: + self._assets = self._makeListOfClassesAttribute( + github.GitReleaseAsset.GitReleaseAsset, attributes["assets"] + ) diff --git a/github/GitRelease.pyi b/github/GitRelease.pyi index d6f292cd..00e63361 100644 --- a/github/GitRelease.pyi +++ b/github/GitRelease.pyi @@ -11,6 +11,8 @@ class GitRelease(CompletableGithubObject): def _initAttributes(self) -> None: ... def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... @property + def assets(self) -> list[GitReleaseAsset]: ... + @property def author(self) -> NamedUser: ... @property def body(self) -> str: ... diff --git a/tests/GitRelease.py b/tests/GitRelease.py index 78287022..7a6a5722 100644 --- a/tests/GitRelease.py +++ b/tests/GitRelease.py @@ -156,6 +156,12 @@ class GitRelease(Framework.TestCase): ), ) self.assertEqual(repr(release), 'GitRelease(title="Test")') + self.assertEqual(len(release.assets), 1) + self.assertEqual( + repr(release.assets[0]), + 'GitReleaseAsset(url="https://api.github.com/repos/' + f'{user}/{repo_name}/releases/assets/{release.raw_data["assets"][0]["id"]}")', + ) def testGetRelease(self): release_by_id = self.release