Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .filplusignore in Allocator repos #226

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fplus-lib/src/core/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 30 additions & 1 deletion fplus-lib/src/external_services/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -779,4 +780,32 @@ impl GithubWrapper {

Ok(contents_items)
}

pub async fn filplus_ignored_files(&self, branch: &str) -> Result<Vec<String>, 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())
})
}
}
4 changes: 1 addition & 3 deletions fplus-lib/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading