@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
7
7
use tracing as log;
8
8
9
9
pub ( crate ) static CONFIG_FILE_NAME : & str = "triagebot.toml" ;
10
- const REFRESH_EVERY : Duration = Duration :: from_secs ( 2 * 60 ) ; // Every two minutes
10
+ const REFRESH_EVERY_SECS : Duration = Duration :: from_secs ( 2 * 60 ) ; // Every two minutes
11
11
12
12
static CONFIG_CACHE : LazyLock <
13
13
RwLock < HashMap < String , ( Result < Arc < Config > , ConfigurationError > , Instant ) > > ,
@@ -440,7 +440,7 @@ pub(crate) async fn get(
440
440
config
441
441
} else {
442
442
log:: trace!( "fetching fresh config for {}" , repo. full_name) ;
443
- let res = get_fresh_config ( gh, repo) . await ;
443
+ let res = get_fresh_config2 ( gh, repo) . await ;
444
444
CONFIG_CACHE
445
445
. write ( )
446
446
. unwrap ( )
@@ -525,14 +525,40 @@ fn default_true() -> bool {
525
525
fn get_cached_config ( repo : & str ) -> Option < Result < Arc < Config > , ConfigurationError > > {
526
526
let cache = CONFIG_CACHE . read ( ) . unwrap ( ) ;
527
527
cache. get ( repo) . and_then ( |( config, fetch_time) | {
528
- if fetch_time. elapsed ( ) < REFRESH_EVERY {
528
+ if fetch_time. elapsed ( ) < REFRESH_EVERY_SECS {
529
529
Some ( config. clone ( ) )
530
530
} else {
531
531
None
532
532
}
533
533
} )
534
534
}
535
535
536
+ async fn get_fresh_config2 (
537
+ _gh : & GithubClient ,
538
+ repo : & Repository ,
539
+ ) -> Result < Arc < Config > , ConfigurationError > {
540
+ let mut content_items = octocrab:: instance ( )
541
+ . repos ( repo. owner ( ) , repo. name ( ) )
542
+ . get_content ( )
543
+ . path ( CONFIG_FILE_NAME )
544
+ . r#ref ( & repo. default_branch )
545
+ . send ( )
546
+ . await
547
+ . map_err ( |e| ConfigurationError :: Http ( Arc :: new ( e. into ( ) ) ) ) ?;
548
+
549
+ let contents = content_items. take_items ( ) ;
550
+ let c = & contents[ 0 ] ;
551
+
552
+ let contents = c
553
+ . decoded_content ( )
554
+ . ok_or ( ConfigurationError :: Missing )
555
+ . map_err ( |e| e) ?;
556
+
557
+ let config = Arc :: new ( toml:: from_str :: < Config > ( & contents) . map_err ( ConfigurationError :: Toml ) ?) ;
558
+ log:: debug!( "fresh configuration for {}: {:?}" , repo. full_name, config) ;
559
+ Ok ( config)
560
+ }
561
+
536
562
async fn get_fresh_config (
537
563
gh : & GithubClient ,
538
564
repo : & Repository ,
0 commit comments