From 3ed2c220f117adfedb32f251631906b505d32c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 14 Aug 2024 09:29:57 +0200 Subject: [PATCH] Set prerelease value when manually updated (#3972) * Set prerelease value when manually updated * Update custom_components/hacs/repositories/base.py --- custom_components/hacs/repositories/base.py | 27 ++++++++++++++----- .../test_download_repository.json | 1 + .../test_update_repository_entity.json | 1 + .../test_update_repository_websocket.json | 1 + .../integration/data.json | 1 + .../hacs-test-org/integration-basic/data.json | 1 + .../integration/404.json | 1 + .../integration/CancelledError.json | 1 + .../integration/TimeoutError.json | 1 + .../integration/error2.json | 1 + 10 files changed, 29 insertions(+), 7 deletions(-) diff --git a/custom_components/hacs/repositories/base.py b/custom_components/hacs/repositories/base.py index 0ee3487e9c5..4b0dabede64 100644 --- a/custom_components/hacs/repositories/base.py +++ b/custom_components/hacs/repositories/base.py @@ -1105,15 +1105,28 @@ async def common_update_data( # Get releases. if not skip_releases: try: - releases = await self.get_releases( - prerelease=self.data.show_beta, - returnlimit=self.hacs.configuration.release_limit, - ) + releases = await self.get_releases(prerelease=True, returnlimit=30) if releases: + self.data.prerelease = None + for release in releases: + if release.draft: + continue + elif release.prerelease: + if self.data.prerelease is None: + self.data.prerelease = release.tag_name + else: + self.data.last_version = release.tag_name + break + self.data.releases = True - self.releases.objects = releases - self.data.published_tags = [x.tag_name for x in self.releases.objects] - self.data.last_version = next(iter(self.data.published_tags)) + + filtered_releases = [ + release + for release in releases + if not release.draft and (self.data.show_beta or not release.prerelease) + ] + self.releases.objects = filtered_releases + self.data.published_tags = [x.tag_name for x in filtered_releases] except HacsException: self.data.releases = False diff --git a/tests/snapshots/hacs-test-org/integration-basic/test_download_repository.json b/tests/snapshots/hacs-test-org/integration-basic/test_download_repository.json index d8a256759db..f68fe9b0abb 100644 --- a/tests/snapshots/hacs-test-org/integration-basic/test_download_repository.json +++ b/tests/snapshots/hacs-test-org/integration-basic/test_download_repository.json @@ -24,6 +24,7 @@ "last_updated": "2011-01-26T19:06:43Z", "last_version": "1.0.0", "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "published_tags": [ "1.0.0" ], diff --git a/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_entity.json b/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_entity.json index fac8120e2ea..64766c74a7a 100644 --- a/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_entity.json +++ b/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_entity.json @@ -24,6 +24,7 @@ "last_updated": "2011-01-26T19:06:43Z", "last_version": "1.0.0", "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "published_tags": [ "1.0.0" ], diff --git a/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_websocket.json b/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_websocket.json index 34e400342a3..b72dc579b8f 100644 --- a/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_websocket.json +++ b/tests/snapshots/hacs-test-org/integration-basic/test_update_repository_websocket.json @@ -24,6 +24,7 @@ "last_updated": "2011-01-26T19:06:43Z", "last_version": "1.0.0", "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "published_tags": [ "1.0.0" ], diff --git a/tests/snapshots/scripts/data/generate_category_data/integration/data.json b/tests/snapshots/scripts/data/generate_category_data/integration/data.json index 183a776ae53..5a8c46b918d 100644 --- a/tests/snapshots/scripts/data/generate_category_data/integration/data.json +++ b/tests/snapshots/scripts/data/generate_category_data/integration/data.json @@ -11,6 +11,7 @@ "name": "Proxy manifest" }, "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api", diff --git a/tests/snapshots/scripts/data/generate_category_data/single/integration/hacs-test-org/integration-basic/data.json b/tests/snapshots/scripts/data/generate_category_data/single/integration/hacs-test-org/integration-basic/data.json index e1a74ab98e5..0a386987616 100644 --- a/tests/snapshots/scripts/data/generate_category_data/single/integration/hacs-test-org/integration-basic/data.json +++ b/tests/snapshots/scripts/data/generate_category_data/single/integration/hacs-test-org/integration-basic/data.json @@ -11,6 +11,7 @@ "name": "Proxy manifest" }, "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api", diff --git a/tests/snapshots/scripts/data/test_generate_category_data_error_status_release/integration/404.json b/tests/snapshots/scripts/data/test_generate_category_data_error_status_release/integration/404.json index 9ca0e93dbf4..2af361c58d9 100644 --- a/tests/snapshots/scripts/data/test_generate_category_data_error_status_release/integration/404.json +++ b/tests/snapshots/scripts/data/test_generate_category_data_error_status_release/integration/404.json @@ -12,6 +12,7 @@ "name": "Proxy manifest" }, "manifest_name": "Proxy manifest", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api", diff --git a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/CancelledError.json b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/CancelledError.json index e7a7a634049..38434961a7d 100644 --- a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/CancelledError.json +++ b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/CancelledError.json @@ -10,6 +10,7 @@ "last_version": "1.0.0", "manifest": {}, "manifest_name": "Basic integration", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api", diff --git a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/TimeoutError.json b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/TimeoutError.json index e7a7a634049..38434961a7d 100644 --- a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/TimeoutError.json +++ b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/TimeoutError.json @@ -10,6 +10,7 @@ "last_version": "1.0.0", "manifest": {}, "manifest_name": "Basic integration", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api", diff --git a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/error2.json b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/error2.json index e7a7a634049..38434961a7d 100644 --- a/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/error2.json +++ b/tests/snapshots/scripts/data/test_generate_category_data_errors_release/integration/error2.json @@ -10,6 +10,7 @@ "last_version": "1.0.0", "manifest": {}, "manifest_name": "Basic integration", + "prerelease": "3.0.0", "stargazers_count": 80, "topics": [ "api",