diff --git a/fplus-lib/src/core/allocator/mod.rs b/fplus-lib/src/core/allocator/mod.rs index 48571b35..27ce2be1 100644 --- a/fplus-lib/src/core/allocator/mod.rs +++ b/fplus-lib/src/core/allocator/mod.rs @@ -473,7 +473,12 @@ pub async fn force_update_allocators( let gh = GithubWrapper::new(allocator.owner, allocator.repo, allocator.installation_id); - for file in files.iter() { + let ignored_files = gh.filplus_ignored_files(branch).await?; + log::debug!("List of ignored files: {ignored_files:?}"); + + let files = files.iter().filter(|f| !ignored_files.contains(f)); + + for file in files { match gh .get_files_from_public_repo( &allocator_template_owner, diff --git a/fplus-lib/src/external_services/github.rs b/fplus-lib/src/external_services/github.rs index 756c0473..bc2d7273 100644 --- a/fplus-lib/src/external_services/github.rs +++ b/fplus-lib/src/external_services/github.rs @@ -12,13 +12,14 @@ use octocrab::models::{IssueState, Label}; use octocrab::params::{pulls::State as PullState, State}; use octocrab::service::middleware::base_uri::BaseUriLayer; use octocrab::service::middleware::extra_headers::ExtraHeadersLayer; -use octocrab::{AuthState, Error as OctocrabError, Octocrab, OctocrabBuilder, Page}; +use octocrab::{AuthState, Error as OctocrabError, GitHubError, Octocrab, OctocrabBuilder, Page}; use serde::{Deserialize, Serialize}; use std::sync::Arc; use crate::config::get_env_var_or_default; use crate::core::application::file::AppState; +use crate::error::LDNError; const GITHUB_API_URL: &str = "https://api.github.com"; @@ -779,4 +780,32 @@ impl GithubWrapper { Ok(contents_items) } + + pub async fn filplus_ignored_files(&self, branch: &str) -> Result, LDNError> { + self.get_file(".filplusignore", branch) + .await + .or_else(|e| match e { + octocrab::Error::GitHub { + source: GitHubError { message, .. }, + .. + } if message == "Not Found" => Ok(ContentItems { items: vec![] }), + _ => Err(e), + }) + .map_err(|e| { + LDNError::Load(format!( + "Failed to load .filplusignore file from repository {}/{}: {}", + self.owner, self.repo, e + )) + })? + .take_items() + .pop() + .map_or(Ok(vec![]), |c| { + Ok(c.decoded_content() + .unwrap_or_default() + .split(&['\n', '\r']) + .map(|v| v.trim().to_string()) + .filter(|v| !v.is_empty()) + .collect()) + }) + } } diff --git a/fplus-lib/src/helpers.rs b/fplus-lib/src/helpers.rs index 4d856c0d..3641d124 100644 --- a/fplus-lib/src/helpers.rs +++ b/fplus-lib/src/helpers.rs @@ -37,9 +37,7 @@ pub fn compare_allowance_and_allocation( pub fn process_amount(mut amount: String) -> String { // Trim 'S' or 's' from the end of the string - amount = amount - .trim_end_matches(|c: char| c == 'S' || c == 's') - .to_string(); + amount = amount.trim_end_matches(['s', 'S']).to_string(); // Replace 'b' with 'B' amount.replace('b', "B")