Skip to content

Commit

Permalink
chore: don't download draft releases (#771)
Browse files Browse the repository at this point in the history
## 🔧 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
#768.

## 🍰 Solution

Filter out releases that are draft.


## 🏝️ 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).
  • Loading branch information
vjousse authored Sep 26, 2024
1 parent 7992844 commit 1f68b23
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bin/download_github_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -68,13 +72,24 @@ 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:
if "-dist.tar.gz" in asset.browser_download_url:
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"
Expand Down

0 comments on commit 1f68b23

Please sign in to comment.