Clones a GitHub repository to a specified directory. Args: repo (str): The GitHub repository to clone. commit (str): The commit to checkout. root_dir (str): The root directory to clone the repository to. token (str): The GitHub personal access token to use f
(repo, commit, root_dir, token, logger)
| 59 | return python_path |
| 60 | |
| 61 | def clone_repo(repo, commit, root_dir, token, logger): |
| 62 | """ |
| 63 | Clones a GitHub repository to a specified directory. |
| 64 | |
| 65 | Args: |
| 66 | repo (str): The GitHub repository to clone. |
| 67 | commit (str): The commit to checkout. |
| 68 | root_dir (str): The root directory to clone the repository to. |
| 69 | token (str): The GitHub personal access token to use for authentication. |
| 70 | |
| 71 | Returns: |
| 72 | Path: The path to the cloned repository directory. |
| 73 | """ |
| 74 | repo_dir = Path(root_dir, f"repo__{repo.replace('/', '__')}__commit__{commit}") |
| 75 | |
| 76 | if not repo_dir.exists(): |
| 77 | repo_url = f"https://{token}@github.com/{repo}.git" |
| 78 | # logger.info(f"Cloning {repo} {os.getpid()}") |
| 79 | Repo.clone_from(repo_url, repo_dir) |
| 80 | cmd = f"cd {repo_dir} && git reset --hard {commit} && git clean -fdxq" |
| 81 | subprocess.run( |
| 82 | cmd, |
| 83 | shell=True, |
| 84 | check=True, |
| 85 | stdout=subprocess.DEVNULL, |
| 86 | stderr=subprocess.DEVNULL, |
| 87 | ) |
| 88 | return root_dir + "/" + repo_dir.name |
| 89 | |
| 90 | def identify_extension(language): |
| 91 | """ |