@@ -13,7 +13,7 @@ use std::fmt;
13
13
pub trait RepositoryForge {
14
14
/// Result used both as the `host` column in the DB and to match repository URLs during
15
15
/// backfill.
16
- fn host ( & self ) -> & str ;
16
+ fn host ( & self ) -> & ' static str ;
17
17
18
18
/// FontAwesome icon used in the front-end.
19
19
fn icon ( & self ) -> & ' static str ;
@@ -56,11 +56,11 @@ pub struct RepositoryStatsUpdater {
56
56
57
57
impl fmt:: Debug for RepositoryStatsUpdater {
58
58
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
59
- write ! (
60
- f ,
61
- "RepositoryStatsUpdater {{ {:?} }}" ,
62
- self . updaters . iter ( ) . map ( |u| u . host ( ) ) . collect :: < Vec <_>> ( )
63
- )
59
+ write ! ( f , "RepositoryStatsUpdater {{ updaters: " ) ? ;
60
+ f . debug_list ( )
61
+ . entries ( self . updaters . iter ( ) . map ( |u| u . host ( ) ) )
62
+ . finish ( ) ? ;
63
+ write ! ( f , " }}" )
64
64
}
65
65
}
66
66
@@ -104,14 +104,21 @@ impl RepositoryStatsUpdater {
104
104
) ? {
105
105
return Ok ( Some ( row. get ( "id" ) ) ) ;
106
106
}
107
- for updater in self . updaters . iter ( ) . filter ( |u| u. host ( ) == name. host ) {
107
+ if let Some ( updater) = self . updaters . iter ( ) . find ( |u| u. host ( ) == name. host ) {
108
108
let res = match updater. fetch_repository ( & name) {
109
109
Ok ( Some ( repo) ) => self . store_repository ( conn, updater. host ( ) , repo) ,
110
+ Ok ( None ) => {
111
+ warn ! (
112
+ "failed to fetch repository `{}` on host `{}`" ,
113
+ url,
114
+ updater. host( )
115
+ ) ;
116
+ return Ok ( None ) ;
117
+ }
110
118
Err ( err) => {
111
119
warn ! ( "failed to collect `{}` stats: {}" , updater. host( ) , err) ;
112
120
return Ok ( None ) ;
113
121
}
114
- _ => continue ,
115
122
} ;
116
123
return match res {
117
124
Ok ( repo_id) => Ok ( Some ( repo_id) ) ,
@@ -148,6 +155,8 @@ impl RepositoryStatsUpdater {
148
155
) ;
149
156
continue ;
150
157
}
158
+ // FIXME: The collect can be avoided if we use Itertools::chunks:
159
+ // https://docs.rs/itertools/0.10.0/itertools/trait.Itertools.html#method.chunks.
151
160
for chunk in needs_update. chunks ( updater. chunk_size ( ) ) {
152
161
let res = updater. fetch_repositories ( chunk) ?;
153
162
for node in res. missing {
@@ -301,45 +310,77 @@ mod test {
301
310
302
311
#[ test]
303
312
fn test_repository_name ( ) {
304
- macro_rules! assert_name {
305
- ( $url: expr => ( $owner: expr, $repo: expr, $host: expr) ) => {
306
- assert_eq!(
307
- repository_name( $url) ,
308
- Some ( RepositoryName {
309
- owner: $owner,
310
- repo: $repo,
311
- host: $host,
312
- } )
313
- ) ;
314
- } ;
315
- ( $url: expr => None ) => {
316
- assert_eq!( repository_name( $url) , None ) ;
317
- } ;
313
+ fn assert_name ( url : & str , data : Option < ( & str , & str , & str ) > ) {
314
+ assert_eq ! (
315
+ repository_name( url) ,
316
+ data. map( |( owner, repo, host) | RepositoryName { owner, repo, host } ) ,
317
+ ) ;
318
318
}
319
319
320
320
// gitlab checks
321
- assert_name ! ( "https://gitlab.com/onur/cratesfyi" => ( "onur" , "cratesfyi" , "gitlab.com" ) ) ;
322
- assert_name ! ( "http://gitlab.com/onur/cratesfyi" => ( "onur" , "cratesfyi" , "gitlab.com" ) ) ;
323
- assert_name ! ( "https://gitlab.com/onur/cratesfyi.git" => ( "onur" , "cratesfyi" , "gitlab.com" ) ) ;
324
- assert_name ! ( "https://gitlab.com/docopt/docopt.rs" => ( "docopt" , "docopt.rs" , "gitlab.com" ) ) ;
325
- assert_name ! ( "https://gitlab.com/onur23cmD_M_R_L_/crates_fy-i" => (
326
- "onur23cmD_M_R_L_" , "crates_fy-i" , "gitlab.com"
327
- ) ) ;
328
- assert_name ! ( "https://gitlab.freedesktop.org/test/test" => (
329
- "test" , "test" , "gitlab.freedesktop.org"
330
- ) ) ;
331
- assert_name ! ( "https://gitlab.com/artgam3s/public-libraries/rust/rpa" => (
332
- "artgam3s/public-libraries/rust" , "rpa" , "gitlab.com"
333
- ) ) ;
321
+ assert_name (
322
+ "https://gitlab.com/onur/cratesfyi" ,
323
+ Some ( ( "onur" , "cratesfyi" , "gitlab.com" ) ) ,
324
+ ) ;
325
+ assert_name (
326
+ "http://gitlab.com/onur/cratesfyi" ,
327
+ Some ( ( "onur" , "cratesfyi" , "gitlab.com" ) ) ,
328
+ ) ;
329
+ assert_name (
330
+ "https://gitlab.com/onur/cratesfyi.git" ,
331
+ Some ( ( "onur" , "cratesfyi" , "gitlab.com" ) ) ,
332
+ ) ;
333
+ assert_name (
334
+ "https://gitlab.com/docopt/docopt.rs" ,
335
+ Some ( ( "docopt" , "docopt.rs" , "gitlab.com" ) ) ,
336
+ ) ;
337
+ assert_name (
338
+ "https://gitlab.com/onur23cmD_M_R_L_/crates_fy-i" ,
339
+ Some ( ( "onur23cmD_M_R_L_" , "crates_fy-i" , "gitlab.com" ) ) ,
340
+ ) ;
341
+ assert_name (
342
+ "https://gitlab.freedesktop.org/test1/test2" ,
343
+ Some ( ( "test1" , "test2" , "gitlab.freedesktop.org" ) ) ,
344
+ ) ;
345
+ assert_name (
346
+ "https://gitlab.com/artgam3s/public-libraries/rust/rpa" ,
347
+ Some ( ( "artgam3s/public-libraries/rust" , "rpa" , "gitlab.com" ) ) ,
348
+ ) ;
349
+
350
+ assert_name ( "https://gitlab.com/moi/" , None ) ;
351
+ assert_name ( "https://gitlab.com/moi" , None ) ;
352
+ assert_name ( "https://gitlab.com" , None ) ;
353
+ assert_name ( "https://gitlab.com/" , None ) ;
334
354
335
355
// github checks
336
- assert_name ! ( "https://github.com/onur/cratesfyi" => ( "onur" , "cratesfyi" , "github.com" ) ) ;
337
- assert_name ! ( "http://github.com/onur/cratesfyi" => ( "onur" , "cratesfyi" , "github.com" ) ) ;
338
- assert_name ! ( "https://github.com/onur/cratesfyi.git" => ( "onur" , "cratesfyi" , "github.com" ) ) ;
339
- assert_name ! ( "https://github.com/docopt/docopt.rs" => ( "docopt" , "docopt.rs" , "github.com" ) ) ;
340
- assert_name ! ( "https://github.com/onur23cmD_M_R_L_/crates_fy-i" => (
341
- "onur23cmD_M_R_L_" , "crates_fy-i" , "github.com"
342
- ) ) ;
356
+ assert_name (
357
+ "https://github.com/onur/cratesfyi" ,
358
+ Some ( ( "onur" , "cratesfyi" , "github.com" ) ) ,
359
+ ) ;
360
+ assert_name (
361
+ "http://github.com/onur/cratesfyi" ,
362
+ Some ( ( "onur" , "cratesfyi" , "github.com" ) ) ,
363
+ ) ;
364
+ assert_name (
365
+ "https://github.com/onur/cratesfyi.git" ,
366
+ Some ( ( "onur" , "cratesfyi" , "github.com" ) ) ,
367
+ ) ;
368
+ assert_name (
369
+ "https://github.com/docopt/docopt.rs" ,
370
+ Some ( ( "docopt" , "docopt.rs" , "github.com" ) ) ,
371
+ ) ;
372
+ assert_name (
373
+ "https://github.com/onur23cmD_M_R_L_/crates_fy-i" ,
374
+ Some ( ( "onur23cmD_M_R_L_" , "crates_fy-i" , "github.com" ) ) ,
375
+ ) ;
376
+
377
+ assert_name ( "https://github.com/moi/" , None ) ;
378
+ assert_name ( "https://github.com/moi" , None ) ;
379
+ assert_name ( "https://github.com" , None ) ;
380
+ assert_name ( "https://github.com/" , None ) ;
381
+
382
+ // Unknown host
383
+ assert_name ( "https://git.sr.ht/~ireas/merge-rs" , None ) ;
343
384
}
344
385
345
386
#[ test]
0 commit comments