Compare commits
2 Commits
cb50649d85
...
3bd86bac98
Author | SHA1 | Date |
---|---|---|
Wynd | 3bd86bac98 | |
Wynd | 8e1eaf4a03 |
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@ cargo-features = ["codegen-backend"]
|
|||
|
||||
[package]
|
||||
name = "git-heatmap"
|
||||
version = "1.0.3"
|
||||
version = "1.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Wynd <wyndftw@proton.me>"]
|
||||
description = "A simple and customizable heatmap for git repos"
|
||||
|
@ -16,11 +16,11 @@ license = "MIT"
|
|||
unsafe_code = { level = "forbid" }
|
||||
|
||||
[dependencies]
|
||||
gix = { version = "0.64.0" }
|
||||
clap = { version = "4.5.13", features = ["derive"] }
|
||||
gix = { version = "0.66.0", default-features = false, features = ["mailmap"] }
|
||||
clap = { version = "4.5.20", features = ["derive"] }
|
||||
chrono = { version = "0.4.38" }
|
||||
itertools = { version = "0.13.0" }
|
||||
anyhow = { version = "1.0.86" }
|
||||
anyhow = { version = "1.0.89" }
|
||||
|
||||
[profile.dev]
|
||||
codegen-backend = "cranelift"
|
||||
|
|
|
@ -65,6 +65,11 @@ $ git-heatmap --split-months
|
|||
# the amount of commits in that day
|
||||
$ git-heatmap --counting by-amount
|
||||
|
||||
# by default the format uses characters to represent days and colors them based on how many commits
|
||||
# that day has, using the numbers format replaces those characters with the actual number of commits
|
||||
# maxed at 99
|
||||
$ git-heatmap --format numbers
|
||||
|
||||
# filter by one or multiple authors (respecting the .mailmap settings)
|
||||
# without an -a flag all authors will be checked
|
||||
$ git-heatmap -a "username" -a "other"
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[toolchain]
|
||||
channel= "nightly"
|
||||
channel = "nightly"
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
|||
use chrono::{Duration, Local};
|
||||
use clap::{arg, Parser, ValueHint};
|
||||
|
||||
use crate::heatmap::{ColorLogic, HeatmapColors};
|
||||
use crate::heatmap::{ColorLogic, Format, HeatmapColors};
|
||||
|
||||
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
|
||||
#[command(version, about, author, long_about = None)]
|
||||
|
@ -43,6 +43,9 @@ pub struct CliArgs {
|
|||
|
||||
#[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByWeight)]
|
||||
pub counting: ColorLogic,
|
||||
|
||||
#[arg(short, long("format"), value_enum, default_value_t = Format::Chars)]
|
||||
pub format: Format,
|
||||
}
|
||||
|
||||
fn get_since_date() -> String {
|
||||
|
|
|
@ -14,6 +14,8 @@ pub struct Heatmap {
|
|||
months: Vec<(usize, String)>,
|
||||
highest_count: i32,
|
||||
repos: usize,
|
||||
|
||||
format: Format,
|
||||
}
|
||||
|
||||
impl Heatmap {
|
||||
|
@ -23,6 +25,7 @@ impl Heatmap {
|
|||
repos: usize,
|
||||
commits: Vec<Commit>,
|
||||
split_months: bool,
|
||||
format: Format,
|
||||
) -> Self {
|
||||
let mut heatmap = Self {
|
||||
data: [vec![], vec![], vec![], vec![], vec![], vec![], vec![]],
|
||||
|
@ -32,6 +35,7 @@ impl Heatmap {
|
|||
months: vec![],
|
||||
highest_count: 0,
|
||||
repos,
|
||||
format,
|
||||
};
|
||||
|
||||
let mut grouped_commits = BTreeMap::new();
|
||||
|
@ -95,9 +99,15 @@ impl Heatmap {
|
|||
let mut row = " ".to_string();
|
||||
|
||||
let mut last_index = 0;
|
||||
let mul = match self.format {
|
||||
Format::Chars => 2,
|
||||
Format::Numbers => 3,
|
||||
};
|
||||
|
||||
for (index, month) in &self.months {
|
||||
let range_size = (index * 2).saturating_sub(last_index * 2).saturating_sub(3);
|
||||
let range_size = (index * mul)
|
||||
.saturating_sub(last_index * mul)
|
||||
.saturating_sub(3);
|
||||
for _i in 0..range_size {
|
||||
row.push(' ');
|
||||
}
|
||||
|
@ -116,11 +126,12 @@ impl Display for Heatmap {
|
|||
let commits = self.commits.len().to_string();
|
||||
let authors = self.commits.iter().unique_by(|c| &c.author.name).count();
|
||||
|
||||
write!(f, "{} - {}\n", start_date, end_date).unwrap();
|
||||
write!(f, "{} repo(s)\n", self.repos).unwrap();
|
||||
write!(f, "{} author(s)\n", authors).unwrap();
|
||||
write!(f, "{} commit(s)\n\n", commits).unwrap();
|
||||
write!(f, "{}\n", self.months_row()).unwrap();
|
||||
writeln!(f, "{} - {}", start_date, end_date).unwrap();
|
||||
writeln!(f, "{} repo(s)", self.repos).unwrap();
|
||||
writeln!(f, "{} author(s)", authors).unwrap();
|
||||
writeln!(f, "{} commit(s)\n", commits).unwrap();
|
||||
|
||||
writeln!(f, "{}", self.months_row()).unwrap();
|
||||
|
||||
for (day, row) in DAYS.iter().zip(&self.data) {
|
||||
write!(f, "{day} ").unwrap();
|
||||
|
@ -128,22 +139,29 @@ impl Display for Heatmap {
|
|||
match val {
|
||||
x if *x >= 0 => {
|
||||
let color = &get_color_map()[get_color(*val, self.highest_count)];
|
||||
write!(f, "{color}{}{RESET} ", get_char()).unwrap();
|
||||
}
|
||||
x if *x < 0 => {
|
||||
write!(f, "{RESET} ").unwrap();
|
||||
match self.format {
|
||||
Format::Chars => write!(f, "{color}{}{RESET} ", get_char()).unwrap(),
|
||||
Format::Numbers => {
|
||||
let val = val.min(&99);
|
||||
write!(f, "{color}{:0>2}{RESET} ", val).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
x if *x < 0 => match self.format {
|
||||
Format::Chars => write!(f, "{RESET} ").unwrap(),
|
||||
Format::Numbers => write!(f, "{RESET} ").unwrap(),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
write!(f, "\n").unwrap();
|
||||
writeln!(f).unwrap();
|
||||
}
|
||||
|
||||
write!(f, "\nLess ").unwrap();
|
||||
for color in get_color_map() {
|
||||
write!(f, "{color}{}{RESET} ", get_char()).unwrap();
|
||||
}
|
||||
write!(f, " More\n").unwrap();
|
||||
writeln!(f, " More").unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -160,3 +178,9 @@ pub enum ColorLogic {
|
|||
ByAmount,
|
||||
ByWeight,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
|
||||
pub enum Format {
|
||||
Chars,
|
||||
Numbers,
|
||||
}
|
||||
|
|
|
@ -84,10 +84,11 @@ fn main() -> Result<()> {
|
|||
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
|
||||
|
||||
let split_months = args.split_months;
|
||||
let format = args.format.clone();
|
||||
|
||||
let commits = get_commits(args, since, until).with_context(|| "Could not fetch commit list")?;
|
||||
|
||||
let heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months);
|
||||
let heatmap = Heatmap::new(since, until, commits.0, commits.1, split_months, format);
|
||||
|
||||
println!("{heatmap}");
|
||||
|
||||
|
|
Loading…
Reference in New Issue