1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
use sqlx;
use tokio;
use reflectub::{database, git, github};
use std::path::Path;
#[tokio::main]
async fn main() {
// let repos = github::fetch_repos().unwrap();
//
// dbg!(&repos);
// git::mirror(
// "https://github.com/teddywing/google-calendar-rsvp.git",
// Path::new("/tmp/grsvp"),
// ).unwrap();
// git::update(
// Path::new("/tmp/grsvp"),
// ).unwrap();
let test_repos = vec![
github::Repo {
id: 18086664,
name: "angular.js".to_owned(),
description: None,
fork: true,
git_url: "git://github.com/teddywing/angular.js.git".to_owned(),
default_branch: "master".to_owned(),
updated_at: "2014-03-25T06:55:16Z".to_owned(),
},
github::Repo {
id: 312106271,
name: "apple-developer-objc".to_owned(),
description: Some(
"A user script that forces Apple Developer documentation to use Objective-C".to_owned(),
),
fork: false,
git_url: "git://github.com/teddywing/apple-developer-objc.git".to_owned(),
default_branch: "master".to_owned(),
updated_at: "2020-11-11T22:49:53Z".to_owned(),
},
];
let mut db = database::Db::connect("test.db").await.unwrap();
// db.create().await.unwrap();
// If repo !exists
// insert
// mirror
// Else
// Update updated_at
// fetch
for repo in test_repos {
let id = repo.id;
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) => {
if db.repo_is_updated(&db_repo).await.unwrap() {
// TODO: fetch
db.repo_update(&db_repo).await.unwrap();
}
},
Err(database::Error::Db(sqlx::Error::RowNotFound)) => {
mirror(
&repo.git_url,
&clone_path,
repo.description.as_deref(),
).unwrap();
db.repo_insert(db_repo).await.unwrap();
},
e => panic!("{:?}", e),
}
}
}
fn mirror<P: AsRef<Path>>(
url: &str,
clone_path: P,
description: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
// mirror database
// update description
// copy cgitrc
git::mirror(url, clone_path, description)?;
Ok(())
}
|