use crate::github::GithubClient; use anyhow::Context as _; use rust_team_data::v1::{Teams, ZulipMapping, BASE_URL}; use serde::de::DeserializeOwned; async fn by_url(client: &GithubClient, path: &str) -> anyhow::Result { let url = format!("{}{}", BASE_URL, path); for _ in 0i32..3 { let map: Result = client.json(client.raw().get(&url)).await; match map { Ok(v) => return Ok(v), Err(e) => { if e.downcast_ref::() .map_or(false, |e| e.is_timeout()) { continue; } else { return Err(e); } } } } Err(anyhow::anyhow!("Failed to retrieve {} in 3 requests", url)) } pub async fn zulip_map(client: &GithubClient) -> anyhow::Result { by_url(client, "/zulip-map.json") .await .context("team-api: zulip-map.json") } pub async fn teams(client: &GithubClient) -> anyhow::Result { by_url(client, "/teams.json") .await .context("team-api: teams.json") }