Skip to content

Commit

Permalink
Merge pull request #34 from ModelAtlasofTheEarth/copy_files_fix
Browse files Browse the repository at this point in the history
Fix bug when file already exists in repo
  • Loading branch information
dansand authored Oct 27, 2024
2 parents ff02a42 + aa1213a commit 8b2c5ae
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions .github/scripts/copy_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
from github.GithubException import UnknownObjectException

#def copy_files(repo, directory, issue_dict):
# file_keys = ["landing_image", "animation", "graphic_abstract", "model_setup_figure"]
Expand All @@ -19,7 +20,20 @@ def copy_files(repo, directory, issue_dict):

# Skip if the URL is an empty string
if url:
response = requests.get(url)
repo.create_file(directory + file_info["filename"], "add " + file_info["filename"], response.content)
file_path = directory + file_info["filename"]

# Skip if file already exists in repo
file_exists = False
try:
file_content = repo.get_contents(file_path)
file_exists = True
except UnknownObjectException:
file_exists = False

if file_exists:
print(f"Skipping {file_key} as the file already exists")
else:
response = requests.get(url)
repo.create_file(file_path, "add " + file_info["filename"], response.content)
else:
print(f"Skipping {file_key} as the URL is empty")

0 comments on commit 8b2c5ae

Please sign in to comment.