Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions project_processor/gh_processor/github_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,23 @@ def download_github_repo(repo_url: str, branch: str = "main") -> str:
"""
repo_name = repo_url.split("/")[-1].split(".")[0]
repo_path = os.path.abspath(repo_name)

if os.path.exists(repo_path):
repo = Repo(repo_path)
origin = repo.remote('origin')

origin.fetch()

head_ref = f"refs/remotes/origin/{branch}"
if repo.commit() != repo.commit(head_ref) or repo.is_dirty(untracked_files=True):
# Reset the local repository to match the last version on GitHub
repo.git.reset('--hard', 'HEAD')
logger.info(f"Repository {repo_name} is now synced with the last version on GitHub.")
else:
logger.info(f"Repository {repo_name} is already up-to-date.")

else:
Repo.clone_from(repo_url, repo_name, branch=branch)
logger.info(f"Repository '{repo_name}' downloaded successfully!")

Repo.clone_from(repo_url, repo_name, branch=branch)

logger.info(f"Repository '{repo_name}' downloaded successfully!")
return repo_path