Skip to content

Commit

Permalink
Additional info about authors
Browse files Browse the repository at this point in the history
  • Loading branch information
WillyChen123 committed Oct 6, 2019
1 parent 868a95f commit cca43a7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Info {
version: String,
dominant_language: Language,
languages: Vec<(Language, f64)>,
authors: Vec<String>,
authors: Vec<(String, usize, usize)>,
last_change: String,
repo: String,
commits: String,
Expand Down Expand Up @@ -102,12 +102,12 @@ impl fmt::Display for Info {
"Author: "
};

writeln!(buffer, "{}{}", title.color(color).bold(), self.authors[0])?;
writeln!(buffer, "{}{:3}% {:15} {}", title.color(color).bold(), self.authors[0].2, self.authors[0].0, self.authors[0].1)?;

let title = " ".repeat(title.len());

for author in self.authors.iter().skip(1) {
writeln!(buffer, "{}{}", title.color(color).bold(), author)?;
writeln!(buffer, "{}{:3}% {:15} {}", title.color(color).bold(), author.2, author.0, author.1)?;
}
}

Expand Down Expand Up @@ -568,7 +568,7 @@ fn get_configuration(dir: &str) -> Result<Configuration> {
}

// Return first n most active commiters as authors within this project.
fn get_authors(dir: &str, n: usize) -> Vec<String> {
fn get_authors(dir: &str, n: usize) -> Vec<(String, usize, usize)> {
let output = Command::new("git")
.arg("-C")
.arg(dir)
Expand All @@ -579,10 +579,12 @@ fn get_authors(dir: &str, n: usize) -> Vec<String> {

// create map for storing author name as a key and their commit count as value
let mut authors = HashMap::new();
let mut total_commits = 0;
let output = String::from_utf8_lossy(&output.stdout);
for line in output.lines() {
let commit_count = authors.entry(line.to_string()).or_insert(0);
*commit_count += 1;
total_commits += 1;
}

// sort authors by commit count where the one with most commit count is first
Expand All @@ -595,9 +597,9 @@ fn get_authors(dir: &str, n: usize) -> Vec<String> {

// get only authors without their commit count
// and string "'" prefix and suffix
let authors: Vec<String> = authors
let authors: Vec<(String, usize, usize)> = authors
.into_iter()
.map(|(author, _)| author.trim_matches('\'').to_string())
.map(|(author, count)| (author.trim_matches('\'').to_string(), count, count*100/total_commits))
.collect();

authors
Expand Down

0 comments on commit cca43a7

Please sign in to comment.