Added a new option to allow the program to find all git repos from a given root dir
parent
90bd9ac376
commit
9bc5c6174c
|
@ -4,6 +4,10 @@ cargo-features = ["codegen-backend"]
|
||||||
name = "git-heatmap"
|
name = "git-heatmap"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
authors = ["Wynd <wyndftw@proton.me>"]
|
||||||
|
description = "A simple and customizable heatmap for git repos"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://git.pixelatedw.xyz/wynd/git-heatmap"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,11 @@ $ git-heatmap -r "/path/to/repo" -b "main" -r "/other/repo" -b "test"
|
||||||
# or to comply with the same number of branch lists per repo lists rule from above
|
# or to comply with the same number of branch lists per repo lists rule from above
|
||||||
$ git-heatmap -r "/path/to/repo" -b "main" -r "other/repo" -b ""
|
$ git-heatmap -r "/path/to/repo" -b "main" -r "other/repo" -b ""
|
||||||
|
|
||||||
|
# alternatively you can simply pass a root directory and let the program search for all git projects
|
||||||
|
# do be warned that doing so means you're losing the customization aspect of choosing
|
||||||
|
# which branches should be checked per repo, in this case all branches will be checked.
|
||||||
|
$ git-heatmap --root-dir "/path"
|
||||||
|
|
||||||
# by default merges are counted so using --no-merges ensures they won't be counted
|
# by default merges are counted so using --no-merges ensures they won't be counted
|
||||||
$ git-heatmap --no-merges
|
$ git-heatmap --no-merges
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,11 @@ use clap::{arg, Parser, ValueHint};
|
||||||
use crate::heatmap::{ColorLogic, HeatmapColors};
|
use crate::heatmap::{ColorLogic, HeatmapColors};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
|
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, author, long_about = None)]
|
||||||
pub struct CliArgs {
|
pub struct CliArgs {
|
||||||
|
#[arg(long("root-dir"), value_hint = ValueHint::DirPath)]
|
||||||
|
pub root_dir: Option<PathBuf>,
|
||||||
|
|
||||||
#[arg(short, long, num_args(0..))]
|
#[arg(short, long, num_args(0..))]
|
||||||
pub authors: Option<Vec<String>>,
|
pub authors: Option<Vec<String>>,
|
||||||
|
|
||||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -2,7 +2,12 @@
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::{cmp::Reverse, collections::HashSet, path::PathBuf, sync::OnceLock};
|
use std::{
|
||||||
|
cmp::Reverse,
|
||||||
|
collections::HashSet,
|
||||||
|
path::{self, PathBuf},
|
||||||
|
sync::OnceLock,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone};
|
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone};
|
||||||
|
@ -84,6 +89,12 @@ fn main() -> Result<()> {
|
||||||
.unwrap_or_else(|| get_default_until(since));
|
.unwrap_or_else(|| get_default_until(since));
|
||||||
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
|
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
|
||||||
|
|
||||||
|
// let mut repo_dirs: Vec<PathBuf> = vec![];
|
||||||
|
// if let Some(root_dir) = &args.root_dir {
|
||||||
|
// find_git_repos(root_dir, &mut repo_dirs, &args);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// dbg!(repo_dirs);
|
||||||
let commits = get_commits(args, since).with_context(|| "Could not fetch commit list")?;
|
let commits = get_commits(args, since).with_context(|| "Could not fetch commit list")?;
|
||||||
|
|
||||||
let heatmap = Heatmap::new(since, until, commits.0, commits.1);
|
let heatmap = Heatmap::new(since, until, commits.0, commits.1);
|
||||||
|
@ -147,9 +158,39 @@ fn get_color_map() -> Vec<String> {
|
||||||
.to_vec()
|
.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn find_git_repos(scan_path: &path::Path, repos: &mut Vec<PathBuf>, _args: &CliArgs) {
|
||||||
|
let Ok(dirs) = scan_path.read_dir()
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let dirs: Vec<_> = dirs
|
||||||
|
.filter_map(|f| f.ok())
|
||||||
|
.filter(|f| f.file_type().is_ok_and(|t| t.is_dir()))
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
let dirs = dirs.iter().map(|f| f.path());
|
||||||
|
|
||||||
|
for dir in dirs {
|
||||||
|
let filename = dir.file_name().unwrap_or_default().to_string_lossy();
|
||||||
|
match filename.as_ref() {
|
||||||
|
".git" => repos.push(dir),
|
||||||
|
_ => find_git_repos(&dir, repos, _args),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commit>)> {
|
fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commit>)> {
|
||||||
let mut commits: HashSet<Commit> = HashSet::new();
|
let mut commits: HashSet<Commit> = HashSet::new();
|
||||||
|
|
||||||
|
let (repos, branches) = match &args.root_dir {
|
||||||
|
Some(root) => {
|
||||||
|
let mut repos: Vec<PathBuf> = vec![];
|
||||||
|
find_git_repos(root, &mut repos, &args);
|
||||||
|
let branches = vec!["".to_string(); repos.len()];
|
||||||
|
(repos, branches)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
let repos = match args.repos {
|
let repos = match args.repos {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => vec![PathBuf::from(".")],
|
None => vec![PathBuf::from(".")],
|
||||||
|
@ -164,6 +205,9 @@ fn get_commits(args: CliArgs, start_date: NaiveDate) -> Result<(usize, Vec<Commi
|
||||||
branches.len()
|
branches.len()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
(repos, branches)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let current_time = Local::now().time();
|
let current_time = Local::now().time();
|
||||||
let start_date = start_date.and_time(current_time);
|
let start_date = start_date.and_time(current_time);
|
||||||
|
|
Loading…
Reference in New Issue