@@ -9,9 +9,10 @@ use tracing as log;
9
9
pub ( crate ) static CONFIG_FILE_NAME : & str = "triagebot.toml" ;
10
10
const REFRESH_EVERY : Duration = Duration :: from_secs ( 2 * 60 ) ; // Every two minutes
11
11
12
- static CONFIG_CACHE : LazyLock <
13
- RwLock < HashMap < String , ( Result < Arc < Config > , ConfigurationError > , Instant ) > > ,
14
- > = LazyLock :: new ( || RwLock :: new ( HashMap :: new ( ) ) ) ;
12
+ type MaybeConfig = Result < Arc < Config > , ConfigurationError > ;
13
+
14
+ static CONFIG_CACHE : LazyLock < RwLock < HashMap < String , ( MaybeConfig , Instant ) > > > =
15
+ LazyLock :: new ( || RwLock :: new ( HashMap :: new ( ) ) ) ;
15
16
16
17
// This struct maps each possible option of the triagebot.toml.
17
18
// See documentation of options at: https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration
@@ -450,10 +451,7 @@ pub(crate) struct ReviewRequestedConfig {
450
451
pub ( crate ) add_labels : Vec < String > ,
451
452
}
452
453
453
- pub ( crate ) async fn get (
454
- gh : & GithubClient ,
455
- repo : & Repository ,
456
- ) -> Result < Arc < Config > , ConfigurationError > {
454
+ pub ( crate ) async fn get ( gh : & GithubClient , repo : & Repository ) -> MaybeConfig {
457
455
if let Some ( config) = get_cached_config ( & repo. full_name ) {
458
456
log:: trace!( "returning config for {} from cache" , repo. full_name) ;
459
457
config
@@ -625,7 +623,7 @@ pub(crate) struct RangeDiffConfig {}
625
623
#[ serde( deny_unknown_fields) ]
626
624
pub ( crate ) struct ReviewChangesSinceConfig { }
627
625
628
- fn get_cached_config ( repo : & str ) -> Option < Result < Arc < Config > , ConfigurationError > > {
626
+ fn get_cached_config ( repo : & str ) -> Option < MaybeConfig > {
629
627
let cache = CONFIG_CACHE . read ( ) . unwrap ( ) ;
630
628
cache. get ( repo) . and_then ( |( config, fetch_time) | {
631
629
if fetch_time. elapsed ( ) < REFRESH_EVERY {
@@ -636,10 +634,7 @@ fn get_cached_config(repo: &str) -> Option<Result<Arc<Config>, ConfigurationErro
636
634
} )
637
635
}
638
636
639
- async fn get_fresh_config (
640
- gh : & GithubClient ,
641
- repo : & Repository ,
642
- ) -> Result < Arc < Config > , ConfigurationError > {
637
+ async fn get_fresh_config ( gh : & GithubClient , repo : & Repository ) -> MaybeConfig {
643
638
let contents = gh
644
639
. raw_file ( & repo. full_name , & repo. default_branch , CONFIG_FILE_NAME )
645
640
. await
0 commit comments