diff --git a/.github/scripts/copy_files.py b/.github/scripts/copy_files.py index 0105830..ad668ad 100644 --- a/.github/scripts/copy_files.py +++ b/.github/scripts/copy_files.py @@ -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"] @@ -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")