Skip to content

Commit 71c18be

Browse files
committed
config: introduce MaybeConfig type alias
pointed out by `clippy::type_complexity`
1 parent bb105b0 commit 71c18be

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/config.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use tracing as log;
99
pub(crate) static CONFIG_FILE_NAME: &str = "triagebot.toml";
1010
const REFRESH_EVERY: Duration = Duration::from_secs(2 * 60); // Every two minutes
1111

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()));
1516

1617
// This struct maps each possible option of the triagebot.toml.
1718
// See documentation of options at: https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration
@@ -450,10 +451,7 @@ pub(crate) struct ReviewRequestedConfig {
450451
pub(crate) add_labels: Vec<String>,
451452
}
452453

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 {
457455
if let Some(config) = get_cached_config(&repo.full_name) {
458456
log::trace!("returning config for {} from cache", repo.full_name);
459457
config
@@ -625,7 +623,7 @@ pub(crate) struct RangeDiffConfig {}
625623
#[serde(deny_unknown_fields)]
626624
pub(crate) struct ReviewChangesSinceConfig {}
627625

628-
fn get_cached_config(repo: &str) -> Option<Result<Arc<Config>, ConfigurationError>> {
626+
fn get_cached_config(repo: &str) -> Option<MaybeConfig> {
629627
let cache = CONFIG_CACHE.read().unwrap();
630628
cache.get(repo).and_then(|(config, fetch_time)| {
631629
if fetch_time.elapsed() < REFRESH_EVERY {
@@ -636,10 +634,7 @@ fn get_cached_config(repo: &str) -> Option<Result<Arc<Config>, ConfigurationErro
636634
})
637635
}
638636

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 {
643638
let contents = gh
644639
.raw_file(&repo.full_name, &repo.default_branch, CONFIG_FILE_NAME)
645640
.await

0 commit comments

Comments
 (0)