Skip to content

Commit

Permalink
feat(history): make git-scanner works with coco
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 4, 2021
1 parent e01ec73 commit 93d307a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
24 changes: 24 additions & 0 deletions src/infrastructure/git/git_file_history.rs
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
use git_scanner::flare::FlareTreeNode;
use git_scanner::git::GitCalculator;
use git_scanner::git_logger::GitLogConfig;
use git_scanner::{file_walker, IndicatorCalculator};
use std::path::PathBuf;

pub fn by_path(root: PathBuf) -> FlareTreeNode {
let mut tics: Vec<Box<dyn IndicatorCalculator>> = vec![];
let calculator = Box::new(GitCalculator::new(
GitLogConfig::default().include_merges(true).since_years(3),
true,
));

tics.push(calculator);

let mut tree = file_walker::walk_directory(&root, &mut tics).unwrap();

for tic in tics {
if let Some(metadata) = tic.metadata().unwrap() {
tree.add_data(tic.name() + "_meta", metadata);
}
}

return tree;
}
28 changes: 7 additions & 21 deletions src/infrastructure/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ mod test {
use crate::infrastructure::git::cmd_git::commit_message;
use crate::infrastructure::git::git_branch::GitBranch;
use crate::infrastructure::git::git_log_parser::GitMessageParser;
use crate::infrastructure::git::GitRepository;
use crate::infrastructure::git::{git_file_history, GitRepository};
use core_model::url_format;
use git_scanner::git::GitCalculator;
use git_scanner::git_logger::GitLogConfig;
use git_scanner::{file_walker, IndicatorCalculator};
use std::fs;

static INIT: Once = Once::new();

Expand Down Expand Up @@ -99,24 +97,12 @@ mod test {
initialize();

let root = url_format::uri_to_path("https://github.com/coco-rs/coco.fixtures");
let tree = git_file_history::by_path(root);

let mut tics: Vec<Box<dyn IndicatorCalculator>> = vec![];
let calculator = Box::new(GitCalculator::new(
GitLogConfig::default().include_merges(true).since_years(3),
true,
));
let json = serde_json::to_string(&tree).unwrap();
fs::write("demo.json", json).unwrap();

tics.push(calculator);

let mut tree = file_walker::walk_directory(&root, &mut tics).unwrap();

for tic in tics {
if let Some(metadata) = tic.metadata().unwrap() {
tree.add_data(tic.name() + "_meta", metadata);
}
}

let output = serde_json::to_string(&tree).unwrap();
println!("{:?}", output);
let name = tree.get_children()[0].name();
assert_eq!("LICENSE", name.to_str().unwrap());
}
}

0 comments on commit 93d307a

Please sign in to comment.