Crates.io | gitstats |
lib.rs | gitstats |
version | 0.0.1-alpha7 |
source | src |
created_at | 2024-02-02 09:32:37.498311 |
updated_at | 2024-02-07 07:21:31.316509 |
description | fetch stats from a git repository |
homepage | https://github.com/sephiroth74/gitstats |
repository | https://github.com/sephiroth74/gitstats |
max_upload_size | |
id | 1124173 |
size | 60,824 |
Generate some stats for git repositories
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 |
+---------------------+---------+--------+