diff options
author | Teddy Wing | 2021-05-30 16:22:11 +0200 |
---|---|---|
committer | Teddy Wing | 2021-05-30 16:23:03 +0200 |
commit | 4ce77f3a6e9d29f60f194fbc31068481e13ff293 (patch) | |
tree | e0825b4fa5d5fcb7b63ebcc72e64d8a2cea0aad7 /src | |
parent | d071c5e456367ed0cc4f907e9e5c7dc46c331399 (diff) | |
download | reflectub-4ce77f3a6e9d29f60f194fbc31068481e13ff293.tar.bz2 |
Clone forks to a `/fork/` path
Separate source and fork repositories into different paths.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index ffda552..d56ffdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use tokio; use reflectub::{database, git, github}; -use std::path::Path; +use std::path::{Path, PathBuf}; #[tokio::main] @@ -58,6 +58,7 @@ async fn main() { for repo in test_repos { let id = repo.id; + let path = clone_path("/tmp", &repo); let db_repo = database::Repo::from(&repo); match db.repo_get(id).await { @@ -70,7 +71,7 @@ async fn main() { }, Err(database::Error::Db(sqlx::Error::RowNotFound)) => { - mirror(&repo).unwrap(); + mirror(&path, &repo).unwrap(); db.repo_insert(db_repo).await.unwrap(); }, @@ -81,14 +82,29 @@ async fn main() { } -fn mirror(repo: &github::Repo) -> anyhow::Result<()> { +fn clone_path<P: AsRef<Path>>(base_path: P, repo: &github::Repo) -> PathBuf { + let git_dir = format!("{}.git", repo.name); + + if repo.fork { + base_path + .as_ref() + .join("fork") + .join(git_dir) + } else { + base_path + .as_ref() + .join(git_dir) + } +} + +fn mirror<P: AsRef<Path>>( + clone_path: P, + repo: &github::Repo, +) -> anyhow::Result<()> { // mirror database // update description // copy cgitrc - let clone_path = Path::new("/tmp") - .join(format!("{}.git", repo.name)); - git::mirror( &repo.git_url, &clone_path, |