@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
77use tracing as log;
88
99pub ( 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
1111
1212static CONFIG_CACHE : LazyLock <
1313 RwLock < HashMap < String , ( Result < Arc < Config > , ConfigurationError > , Instant ) > > ,
@@ -440,7 +440,7 @@ pub(crate) async fn get(
440440 config
441441 } else {
442442 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 ;
444444 CONFIG_CACHE
445445 . write ( )
446446 . unwrap ( )
@@ -525,14 +525,40 @@ fn default_true() -> bool {
525525fn get_cached_config ( repo : & str ) -> Option < Result < Arc < Config > , ConfigurationError > > {
526526 let cache = CONFIG_CACHE . read ( ) . unwrap ( ) ;
527527 cache. get ( repo) . and_then ( |( config, fetch_time) | {
528- if fetch_time. elapsed ( ) < REFRESH_EVERY {
528+ if fetch_time. elapsed ( ) < REFRESH_EVERY_SECS {
529529 Some ( config. clone ( ) )
530530 } else {
531531 None
532532 }
533533 } )
534534}
535535
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+
536562async fn get_fresh_config (
537563 gh : & GithubClient ,
538564 repo : & Repository ,
0 commit comments