From cab04e3c59310d268ecd6e87599c1dad8500d993 Mon Sep 17 00:00:00 2001 From: AttilaGombosER Date: Fri, 6 Sep 2024 15:22:42 +0200 Subject: [PATCH] Fix webhook asset download using API (#13) --- package_collector/releaseSource.py | 13 ++++--------- package_collector/webhookServer.py | 9 +++++---- tests/webhookServerTest.py | 1 + 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/package_collector/releaseSource.py b/package_collector/releaseSource.py index 743edc4..155808a 100644 --- a/package_collector/releaseSource.py +++ b/package_collector/releaseSource.py @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2024 Attila Gombos # SPDX-License-Identifier: MIT -from typing import Optional, Tuple +from typing import Optional from context_logger import get_logger from github.GitRelease import GitRelease @@ -20,12 +20,6 @@ def get_config(self) -> ReleaseConfig: def get_release(self) -> Optional[GitRelease]: raise NotImplementedError() - def get_config_and_release(self) -> Tuple[ReleaseConfig, Optional[GitRelease]]: - raise NotImplementedError() - - def check_release(self) -> bool: - raise NotImplementedError() - def check_latest_release(self) -> bool: raise NotImplementedError() @@ -48,8 +42,9 @@ def check_latest_release(self) -> bool: if latest_release := self._get_release(): if not self._release or self._release.tag_name != latest_release.tag_name: old_tag = self._release.tag_name if self._release else None - log.info('New release found', - repo=self._config.full_name, old_tag=old_tag, new_tag=latest_release.tag_name) + log.info( + 'New release found', repo=self._config.full_name, old_tag=old_tag, new_tag=latest_release.tag_name + ) self._release = latest_release return True diff --git a/package_collector/webhookServer.py b/package_collector/webhookServer.py index 783248c..82d546b 100644 --- a/package_collector/webhookServer.py +++ b/package_collector/webhookServer.py @@ -186,7 +186,8 @@ def _download_asset(self, asset: dict[str, Any], token: Optional[str] = None) -> self._file_downloader.download(asset['url'], asset['name'], headers) def _download_asset_from_api(self, source: IReleaseSource) -> None: - config = source.get_config() - release = source.get_release() - if release: - self._asset_downloader.download(config, release) + if source.check_latest_release(): + config = source.get_config() + release = source.get_release() + if release: + self._asset_downloader.download(config, release) diff --git a/tests/webhookServerTest.py b/tests/webhookServerTest.py index a1dbab9..b0325ed 100644 --- a/tests/webhookServerTest.py +++ b/tests/webhookServerTest.py @@ -204,6 +204,7 @@ def test_returns_200_and_downloads_asset_using_api_when_no_assets_in_release(sel # Then wait_for_assertion(2, asset_downloader.download.assert_called_once_with, source.config, source.release) + source.check_latest_release.assert_called_once() self.assertEqual(200, response.status_code)