use crate::config::Settings;
use crate::task::Task;
use crate::task::task_file_providers::TaskFileProvidersBuilder;
use eyre::{Result, bail};
pub struct TaskFetcher {
no_cache: bool,
}
impl TaskFetcher {
pub fn new(no_cache: bool) -> Self {
Self { no_cache }
}
pub async fn fetch_tasks(&self, tasks: &mut Vec<Task>) -> Result<()> {
let no_cache = self.no_cache || Settings::get().task.remote_no_cache.unwrap_or(false);
let task_file_providers = TaskFileProvidersBuilder::new()
.with_cache(!no_cache)
.build();
for t in tasks {
if let Some(file) = &t.file {
let source = file.to_string_lossy().to_string();
if !Self::is_remote_source(&source) {
continue;
}
let provider = task_file_providers.get_provider(&source);
if provider.is_none() {
bail!("No provider found for file: {}", source);
}
let local_path = provider.unwrap().get_local_path(&source).await?;
t.remote_file_source = Some(source);
t.file = Some(local_path);
}
}
Ok(())
}
pub fn is_remote_source(source: &str) -> bool {
source.starts_with("git::")
|| source.starts_with("http://")
|| source.starts_with("https://")
}
}