Download a GitHub repository archive into a staging directory.
(
url: str,
staging_parent: Path,
on_progress: Optional[Callable[[str], None]] = None,
)
| 274 | |
| 275 | |
| 276 | def prepare_github_archive( |
| 277 | url: str, |
| 278 | staging_parent: Path, |
| 279 | on_progress: Optional[Callable[[str], None]] = None, |
| 280 | ) -> tuple[Path, PluginSourceInfo]: |
| 281 | """Download a GitHub repository archive into a staging directory.""" |
| 282 | owner, repo, ref = parse_github_url(url) |
| 283 | archive_url = github_archive_url(owner, repo, ref) |
| 284 | |
| 285 | if on_progress: |
| 286 | ref_text = f"@{ref}" if ref else "" |
| 287 | on_progress(f"Downloading {owner}/{repo}{ref_text} archive...") |
| 288 | |
| 289 | staging_dir = prepare_archive_from_download_url( |
| 290 | archive_url, |
| 291 | staging_parent, |
| 292 | temp_prefix=f".{repo}-", |
| 293 | request_headers={"Accept": "application/vnd.github+json"}, |
| 294 | ) |
| 295 | return staging_dir, PluginSourceInfo( |
| 296 | transport="archive", |
| 297 | origin=url.strip(), |
| 298 | github_url=github_repo_url(owner, repo), |
| 299 | owner=owner, |
| 300 | repo=repo, |
| 301 | requested_ref=ref or "", |
| 302 | resolved_ref=ref or "", |
| 303 | archive_url=archive_url, |
| 304 | ) |
| 305 | |
| 306 | |
| 307 | class PluginInstaller: |
no test coverage detected