Skip to content

Commit

Permalink
Fix webhook asset download using API (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaGombosER authored Sep 6, 2024
1 parent 79e37a3 commit cab04e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
13 changes: 4 additions & 9 deletions package_collector/releaseSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2024 Attila Gombos <[email protected]>
# SPDX-License-Identifier: MIT

from typing import Optional, Tuple
from typing import Optional

from context_logger import get_logger
from github.GitRelease import GitRelease
Expand All @@ -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()

Expand All @@ -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

Expand Down
9 changes: 5 additions & 4 deletions package_collector/webhookServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/webhookServerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cab04e3

Please sign in to comment.