From d03d3ce5ac4357ab9dc6bf2a994461b855c4232b Mon Sep 17 00:00:00 2001 From: green-green-avk <45503261+green-green-avk@users.noreply.github.com> Date: Sat, 27 Mar 2021 20:44:41 -0700 Subject: [PATCH 1/3] A property to access the `assets` field of release (#1898) ... in order to avoid extra requests. --- github/GitRelease.py | 15 +++++++++++++++ github/GitRelease.pyi | 2 ++ 2 files changed, 17 insertions(+) diff --git a/github/GitRelease.py b/github/GitRelease.py index d62e98fff6..4327e3f7d6 100644 --- a/github/GitRelease.py +++ b/github/GitRelease.py @@ -170,6 +170,16 @@ def zipball_url(self): self._completeIfNotSet(self._zipball_url) return self._zipball_url.value + @property + def assets(self): + """ + Already returned assets info (no additional requests will be done). + + :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 +343,7 @@ def _initAttributes(self): 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 +380,7 @@ def _useAttributes(self, attributes): 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 d6f292cd93..00e633616d 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: ... From af9e704fcdebeaa2a51c6af4a1ea3c585ea9aa55 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 20 Dec 2022 12:20:18 +0100 Subject: [PATCH 2/3] Remove comment to comply the review --- github/GitRelease.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/github/GitRelease.py b/github/GitRelease.py index e6a4b26575..56f56ea287 100644 --- a/github/GitRelease.py +++ b/github/GitRelease.py @@ -173,8 +173,6 @@ def zipball_url(self): @property def assets(self): """ - Already returned assets info (no additional requests will be done). - :type: list of :class:`github.GitReleaseAsset.GitReleaseAsset` """ self._completeIfNotSet(self._assets) From a28f048023a5541ee8cd0b60a1e1221de764c89c Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 20 Dec 2022 12:26:51 +0100 Subject: [PATCH 3/3] Add tests for GitRelease.assets --- tests/GitRelease.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/GitRelease.py b/tests/GitRelease.py index 7828702220..7a6a5722f0 100644 --- a/tests/GitRelease.py +++ b/tests/GitRelease.py @@ -156,6 +156,12 @@ def testAttributes(self): ), ) 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