aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-05-30 15:02:37 +0200
committerTeddy Wing2021-05-30 15:02:37 +0200
commit80a1cda7f857dbb2e776253225446351228072fb (patch)
tree2c56b8cd5ad14c13327bd4027df007078c763341 /src
parentbb57eb9167740b8b14b87aafae3898a2517d0909 (diff)
downloadreflectub-80a1cda7f857dbb2e776253225446351228072fb.tar.bz2
main: Mirror new repositories
If we haven't encountered a repository yet, mirror it to the filesystem. Change `From<github::Repo>` to `From<&github::Repo>` so we don't consume the repo and can use it later in the repo list loop.
Diffstat (limited to 'src')
-rw-r--r--src/database.rs8
-rw-r--r--src/main.rs16
2 files changed, 17 insertions, 7 deletions
diff --git a/src/database.rs b/src/database.rs
index 2a53f0b..c07eca0 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -11,12 +11,12 @@ pub struct Repo {
updated_at: Option<String>,
}
-impl From<github::Repo> for Repo {
- fn from(repo: github::Repo) -> Self {
+impl From<&github::Repo> for Repo {
+ fn from(repo: &github::Repo) -> Self {
Self {
id: repo.id,
- name: Some(repo.name),
- updated_at: Some(repo.updated_at),
+ name: Some(repo.name.clone()),
+ updated_at: Some(repo.updated_at.clone()),
}
}
}
diff --git a/src/main.rs b/src/main.rs
index ea7a45b..478ffab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -57,7 +57,9 @@ async fn main() {
for repo in test_repos {
let id = repo.id;
- let db_repo = database::Repo::from(repo);
+ let clone_path = Path::new("/tmp")
+ .join(format!("{}.git", repo.name));
+ let db_repo = database::Repo::from(&repo);
match db.repo_get(id).await {
Ok(r) => {
@@ -69,7 +71,10 @@ async fn main() {
},
Err(database::Error::Db(sqlx::Error::RowNotFound)) => {
- mirror().unwrap();
+ mirror(
+ &repo.git_url,
+ &clone_path,
+ ).unwrap();
db.repo_insert(db_repo).await.unwrap();
},
@@ -80,10 +85,15 @@ async fn main() {
}
-fn mirror() -> Result<(), Box<dyn std::error::Error>> {
+fn mirror<P: AsRef<Path>>(
+ url: &str,
+ clone_path: P,
+) -> Result<(), Box<dyn std::error::Error>> {
// mirror database
// update description
// copy cgitrc
+ git::mirror(url, clone_path)?;
+
Ok(())
}