Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Jul 29, 2024
1 parent 7be410b commit d1975ad
Show file tree
Hide file tree
Showing 587 changed files with 429 additions and 30,136 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.toml') }}
- uses: actions-rs/cargo@v1.0.3
with:
command: build
args: --release --all-features --manifest-path ./Cargo.toml
command: build
args: --release --all-features --manifest-path ./Cargo.toml
64 changes: 64 additions & 0 deletions Source/Fn/Binary/Command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// Defines and configures command-line arguments for the "Summary" command.
///
/// # Returns
///
/// * `ArgMatches` - The parsed command-line arguments.
///
/// # Example
///
/// ```
/// let matches = Fn();
/// let parallel = matches.get_flag("Parallel");
/// let root = matches.get_one::<String>("Root").unwrap();
/// ```
pub fn Fn() -> ArgMatches {
Command::new("Summary")
.version(env!("CARGO_PKG_VERSION"))
.author("🖋️ Source — 👐🏻 Open — <Source/Open@PlayForm.Cloud>")
.about("🗣️ Summary —")
.arg(
Arg::new("Parallel")
.short('P')
.long("Parallel")
.action(SetTrue)
.display_order(3)
.value_name("PARALLEL")
.required(false)
.help("⏩ Parallel —"),
)
.arg(
Arg::new("Root")
.short('R')
.long("Root")
.display_order(4)
.value_name("ROOT")
.required(false)
.help("📂 Root —")
.default_value("."),
)
.arg(
Arg::new("Exclude")
.short('E')
.long("Exclude")
.display_order(5)
.value_name("EXCLUDE")
.required(false)
.help("🚫 Exclude —")
.default_value("node_modules"),
)
.arg(
Arg::new("Pattern")
.display_order(6)
.value_name("PATTERN")
.required(true)
.help("🔍 Pattern —")
.default_value(".git"),
)
.get_matches()
}

use clap::{Arg, ArgAction::SetTrue, ArgMatches, Command};

pub mod Entry;
pub mod Parallel;
pub mod Sequential;
51 changes: 51 additions & 0 deletions Source/Fn/Binary/Command/Entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// Walks through a directory and filters files based on specified criteria.
///
/// # Arguments
///
/// * `Option` - A struct containing the following fields:
/// * `Exclude`: Vec<String> - List of patterns to exclude
/// * `Pattern`: String - The pattern to match for inclusion
/// * `Root`: String - The root directory to start the walk from
/// * `Separator`: char - The path separator character
///
/// # Returns
///
/// * `Return` - A vector of vectors of strings, where each inner vector represents a file path
/// split into its components.
///
/// # Example
///
/// ```
/// let option = Option {
/// Exclude: vec!["node_modules".to_string()],
/// Pattern: ".git".to_string(),
/// Root: ".".to_string(),
/// Separator: std::path::MAIN_SEPARATOR,
/// };
/// let result = Fn(&option);
/// ```
pub fn Fn(Option { Exclude, Pattern, Root, Separator, .. }: &Option) -> Return {
WalkDir::new(Root)
.follow_links(false)
.into_iter()
.filter_map(|Entry| {
let Path = Entry.expect("Cannot Entry.").path().display().to_string();

// TODO: Separate this into Entry/Exclude.rs
if !Exclude
.clone()
.into_iter()
.filter(|Exclude| *Pattern != *Exclude)
.any(|Exclude| Path.contains(&Exclude))
{
Some(Path.split(*Separator).map(|Entry| Entry.to_string()).collect())
} else {
None
}
})
.collect::<Vec<_>>()
}

use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option};

use walkdir::WalkDir;
53 changes: 53 additions & 0 deletions Source/Fn/Binary/Command/Parallel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// Processes entries in parallel, filtering and executing commands based on specified criteria.
///
/// # Arguments
///
/// * `Option` - A struct containing the following fields:
/// * `Entry`: Vec<Vec<String>> - List of entries to process
/// * `Separator`: char - The path separator character
/// * `Pattern`: String - The pattern to match for inclusion
///
/// # Example
///
/// ```
/// let option = Option {
/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.txt".to_string()]],
/// Separator: '/',
/// Pattern: "file.txt".to_string(),
/// };
/// Fn(option).await;
/// ```
pub async fn Fn(Option { Entry, Separator, Pattern, .. }: Option) {
let Queue: Vec<_> = stream::iter(
Entry
.into_par_iter()
.filter_map(|Entry| {
Entry
.last()
.filter(|Last| *Last == &Pattern)
.map(|_| Entry[0..Entry.len() - 1].join(&Separator.to_string()))
})
.collect::<Vec<String>>(),
)
.map(|Entry| {
tokio::spawn(async move {
match crate::Fn::Summary::Fn(&Entry).await {
Ok(summary) => Ok(summary),
Err(e) => Err(format!("Error generating summary for {}: {}", Entry, e)),
}
})
})
.buffer_unordered(num_cpus::get())
.collect()
.await;

Queue.par_iter().for_each(|Output| match Output {
Ok(Ok(Summary)) => println!("Summary: {:?}", Summary),
Ok(Err(Error)) => eprintln!("Error: {}", Error),
Err(Panic) => eprintln!("Panic: {}", Panic),
});
}

use crate::Struct::Binary::Command::Entry::Struct as Option;
use futures::stream::{self, StreamExt};
use rayon::prelude::*;
34 changes: 34 additions & 0 deletions Source/Fn/Binary/Command/Sequential.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// Processes entries sequentially, filtering and executing commands based on specified criteria.
///
/// # Arguments
///
/// * `Option` - A struct containing the following fields:
/// * `Entry`: Vec<Vec<String>> - List of entries to process
/// * `Pattern`: String - The pattern to match for inclusion
/// * `Separator`: char - The path separator character
///
/// # Example
///
/// ```
/// let option = Option {
/// Entry: vec![vec!["path".to_string(), "to".to_string(), "file.txt".to_string()]],
/// Pattern: "file.txt".to_string(),
/// Separator: '/',
/// };
/// Fn(option);
/// ```
pub fn Fn(Option { Entry, Pattern, Separator, .. }: Option) {
Entry
.into_iter()
.filter_map(|Entry| {
Entry
.last()
.filter(|Last| *Last == &Pattern)
.map(|_| Entry[0..Entry.len() - 1].join(&Separator.to_string()))
})
.for_each(|_Entry| {
// TODO: GENERATE SUMMARY
})
}

use crate::Struct::Binary::Command::Entry::Struct as Option;
55 changes: 55 additions & 0 deletions Source/Fn/Summary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// Generates a summary based on the provided options.
///
/// # Arguments
///
/// * `Option` - A struct containing the necessary information for generating the summary.
///
/// # Returns
///
/// * `Return` - The generated summary.
///
/// # Example
///
/// ```
/// let option = Option {
/// // Fields needed for summary generation
/// };
/// let summary = Fn(&option);
/// ```
pub async fn Fn(Entry: &str) -> Result<(), Box<dyn std::error::Error>> {
let Repository = Repository::open(Entry)?;

let Tag = Repository.tag_names(None)?;
let mut Start = None;

let Summary = "Summary";
fs::create_dir_all(Summary)?;

for i in 0..Tag.len() {
if let Some(Tag) = Tag.get(i) {
if let Some(Start) = Start {
let Difference = crate::Fn::Summary::Difference::Fn(&Repository, Start, Tag)?;

File::create(&format!("{}/Difference_{}_{}.txt", Summary, Start, Tag))?.write_all(
crate::Fn::Summary::Difference::Fn(&Repository, Start, Tag)?.as_bytes(),
)?;

File::create(&format!("{}/Release_{}_{}.txt", Summary, Start, Tag))?
.write_all(crate::Fn::Summary::Release::Fn(&Difference).as_bytes())?;
}

Start = Some(Tag);
}
}

Ok(())
}

use git2::Repository;
use std::{
fs::{self, File},
io::Write,
};

pub mod Difference;
pub mod Release;
33 changes: 33 additions & 0 deletions Source/Fn/Summary/Difference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// Calculates the difference between two summaries.
///
/// # Arguments
///
/// * `Option` - A struct containing the necessary information for calculating the difference.
///
/// # Returns
///
/// * `Return` - The calculated difference between the summaries.
///
/// # Example
///
/// ```
/// let option = Option {
/// // Fields needed for difference calculation
/// };
/// let difference = Fn(&option);
/// ```
pub fn Fn(Repo: &git2::Repository, Start: &str, End: &str) -> Result<String, git2::Error> {
let mut Difference = String::new();

Repo.diff_tree_to_tree(
Some(&Repo.revparse_single(Start)?.peel_to_commit()?.tree()?),
Some(&Repo.revparse_single(End)?.peel_to_commit()?.tree()?),
Some(&mut git2::DiffOptions::new()),
)?
.print(git2::DiffFormat::Patch, |_, _, line| {
Difference.push_str(std::str::from_utf8(line.content()).unwrap());
true
})?;

Ok(Difference)
}
33 changes: 33 additions & 0 deletions Source/Fn/Summary/Release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// Generates a release summary.
///
/// # Arguments
///
/// * `Option` - A struct containing the necessary information for generating the release summary.
///
/// # Returns
///
/// * `Return` - The generated release summary.
///
/// # Example
///
/// ```
/// let option = Option {
/// // Fields needed for release summary generation
/// };
/// let release_summary = Fn(&option);
/// ```
pub fn Fn(Difference: &str) -> String {
let mut Release = String::new();

Release.push_str("Release Notes:\n");

for Difference in Difference.lines() {
if Difference.starts_with("+") && !Difference.starts_with("+++") {
Release.push_str(&format!("Added: {}\n", &Difference[1..]));
} else if Difference.starts_with("-") && !Difference.starts_with("---") {
Release.push_str(&format!("Removed: {}\n", &Difference[1..]));
}
}

Release
}
1 change: 1 addition & 0 deletions Source/Fn/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod Binary;
pub mod Summary;
10 changes: 7 additions & 3 deletions Source/Library.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#![allow(non_snake_case)]

mod Fn;
mod Struct;

/// The main entry point for the Summary application.
///
/// This function initializes the command structure and executes the appropriate
/// command based on the provided command-line arguments.
#[allow(dead_code)]
#[tokio::main]
async fn main() {
(Struct::Binary::Command::Struct::Fn().Fn)().await
}

pub mod Fn;
pub mod Struct;
9 changes: 6 additions & 3 deletions Source/Struct/Binary/Command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// Represents the main command structure for the Summary application.
pub struct Struct {
/// The path separator character.
pub Separator: Option::Separator,
/// A boxed function that returns a pinned future.
pub Fn: Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + 'static>,
}

Expand All @@ -25,10 +28,10 @@ impl Struct {
}
}

pub mod Entry;
pub mod Option;

use crate::Fn::Binary::Command::{Parallel, Sequential};

use futures::Future;
use std::pin::Pin;

pub mod Entry;
pub mod Option;
Loading

0 comments on commit d1975ad

Please sign in to comment.