From 1f68b23ddd4145f71bd65564072421b6bbaaaa3f Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Thu, 26 Sep 2024 17:00:05 +0200 Subject: [PATCH] chore: don't download draft releases (#771) ## :wrench: Problem When deploying on scalingo we download all releases without checking if it's a draft one, it may cause problems if we want to use the draft functionality of releases to use `git-cliff` for example https://github.com/MTES-MCT/ecobalyse/pull/768. ## :cake: Solution Filter out releases that are draft. ## :desert_island: How to test The deploy to scalingo of this PR should download 11 releases and not more (we currently have 11 releases and some drafts). --- bin/download_github_releases.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/download_github_releases.py b/bin/download_github_releases.py index f7339d089..333a8633a 100755 --- a/bin/download_github_releases.py +++ b/bin/download_github_releases.py @@ -26,8 +26,12 @@ def download_file(url, destination_directory=None): logger.debug(f"-> Downloading {url} to {local_filename}") with requests.get(url, stream=True) as r: - with open(local_filename, "wb") as f: - shutil.copyfileobj(r.raw, f) + if r.status_code == 200: + with open(local_filename, "wb") as f: + shutil.copyfileobj(r.raw, f) + else: + logger.error(f"Status: {r.status_code}, body: {r.text}") + return None return local_filename @@ -68,6 +72,11 @@ def download_file(url, destination_directory=None): nb_releases_extracted = 0 for release in releases: if release.tag_name is None: + logger.info("Skipping release without a tag.") + continue + + if release.draft: + logger.info("Skipping draft release.") continue for asset in release.assets: @@ -75,6 +84,12 @@ def download_file(url, destination_directory=None): file_path = download_file( asset.browser_download_url, args.destination_directory ) + if not file_path: + logger.error( + f"Error downloading {asset.browser_download_url}, skipping." + ) + continue + # 'dist' is the name of the directory contained in the archive unpacked_destination_directory = os.path.join( args.destination_directory, "dist"