gitstats

Crates.iogitstats
lib.rsgitstats
version0.0.1-alpha7
sourcesrc
created_at2024-02-02 09:32:37.498311
updated_at2024-02-07 07:21:31.316509
descriptionfetch stats from a git repository
homepagehttps://github.com/sephiroth74/gitstats
repositoryhttps://github.com/sephiroth74/gitstats
max_upload_size
id1124173
size60,824
Alessandro Crugnola (sephiroth74)

documentation

README

gitstats (for Rust)

Generate some stats for git repositories

crates.io

Examples:

Fetch the commits per author


use comfy_table::Table;
use gitstats::{CommitArgs, Repo, SortStatsBy};

fn contributors_stats() {
    let repo = Repo::new("/custom/repo");
    let commits = repo.list_commits(CommitArgs::default()).unwrap();
    let stats = repo.commits_stats(&commits).unwrap();
    let commits_per_author = stats.commits_per_author();
    let mut global_stats = commits_per_author.global_stats(SortStatsBy::LinesAdded);
    global_stats.sort_by(|a,b|b.commits_count.cmp(&a.commits_count));

    let mut table = Table::new();
    table.set_header(["Author", "Commits", "Lines"]);

    for global_stat in global_stats.iter() {
        let commits_count = global_stat.commits_count;
        let total_lines = global_stat.stats.lines_added;
        table.add_row([(&global_stat.author).name.to_string(), commits_count.to_string(), total_lines.to_string()]);
    }

    println!("{}", table);
}

It will print something like this:


 +---------------------+---------+--------+
 | Author              | Commits | Lines  |
 +========================================+
 | John Doe            | 54      | 13355  |
 |---------------------+---------+--------|
 | Jane Doe            | 48      | 1355   |
 |---------------------+---------+--------|
 | Alessandro Crugnola | 45      | 172240 |
 |---------------------+---------+--------|
 | Michael Binary      | 31      | 13845  |
 |---------------------+---------+--------|
 | David One           | 9       | 56     |
 +---------------------+---------+--------+
Commit count: 0

cargo fmt