Skip to content

Commit

Permalink
refactor: gate reviewer/tester stats behind flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehsiao committed Apr 5, 2023
1 parent a353bc1 commit 328a600
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Git Stats parses shortlog information to get stats about the files changed, additions, and
deletions. For example:

$ git stats origin..HEAD
$ git stats -r origin..HEAD
Author Commits Changed Files Insertions Deletions Net Δ
Luke Hsiao 30 50 +1324 -166 +1158

Expand All @@ -34,7 +34,6 @@ cargo install git-stats --locked
## Usage

```
$ git stats -h
A script for grabbing more thorough shortlog stats
Usage: git-stats [OPTIONS] [revision-range]
Expand All @@ -43,7 +42,8 @@ Arguments:
[revision-range] Show only commits in the specified revision range [default: HEAD]
Options:
-e, --email Show the email address of each author
-h, --help Print help information (use `--help` for more detail)
-V, --version Print version information
-e, --email Show the email address of each author
-r, --reviews Show who reviewed/tested commits based on `Acked-by`, `Tested-by`, and `Reviewed-by` git trailers
-h, --help Print help (see more with '--help')
-V, --version Print version
```
60 changes: 33 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ struct Cli {
/// commit (i.e. HEAD), but not from origin. For a complete list of ways to spell
/// [revision-range], see the "Specifying Ranges" section of gitrevisions(7).
rev_range: String,
#[arg(short, long, default_value = "false")]
#[arg(short, long)]
/// Show the email address of each author.
email: bool,
#[arg(short, long)]
/// Show who reviewed/tested commits based on `Acked-by`, `Tested-by`, and
/// `Reviewed-by` git trailers.
reviews: bool,
}

#[derive(Tabled)]
Expand Down Expand Up @@ -139,36 +143,38 @@ fn main() -> Result<()> {
println!("{table}");
}

let raw_reviewers = if cli.email {
cmd!(sh, "git shortlog -sen --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()?
} else {
cmd!(sh, "git shortlog -sn --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()?
};
let reviewers: Vec<(usize, &str)> = raw_reviewers
.lines()
.map(|line| {
let chunks = line.trim().split_once('\t').unwrap();
let commits = usize::from_str(chunks.0).unwrap();
let author = chunks.1;
(commits, author)
})
.collect::<_>();

if !reviewers.is_empty() {
let reviews: Vec<Review> = reviewers
.par_iter()
.map(|(commits, author)| Review {
author: author.to_string(),
commits: *commits,
if cli.reviews {
let raw_reviewers = if cli.email {
cmd!(sh, "git shortlog -sen --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()?
} else {
cmd!(sh, "git shortlog -sn --group=trailer:acked-by --group=trailer:tested-by --group=trailer:reviewed-by {rev_range}").read()?
};
let reviewers: Vec<(usize, &str)> = raw_reviewers
.lines()
.map(|line| {
let chunks = line.trim().split_once('\t').unwrap();
let commits = usize::from_str(chunks.0).unwrap();
let author = chunks.1;
(commits, author)
})
.collect::<_>();

let mut table = Table::new(reviews);
table
.with(Style::empty())
.with(Modify::new(Columns::new(1..=1)).with(Alignment::right()));
if !reviewers.is_empty() {
let reviews: Vec<Review> = reviewers
.par_iter()
.map(|(commits, author)| Review {
author: author.to_string(),
commits: *commits,
})
.collect::<_>();

let mut table = Table::new(reviews);
table
.with(Style::empty())
.with(Modify::new(Columns::new(1..=1)).with(Alignment::right()));

println!("\n{table}");
println!("\n{table}");
}
}

Ok(())
Expand Down

0 comments on commit 328a600

Please sign in to comment.