Skip to content

Commit 05d3788

Browse files
authored
Merge pull request #57 from WillyChen123/authors-info
Additional info about Authors (Contributors)
2 parents 868a95f + cca43a7 commit 05d3788

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Info {
3232
version: String,
3333
dominant_language: Language,
3434
languages: Vec<(Language, f64)>,
35-
authors: Vec<String>,
35+
authors: Vec<(String, usize, usize)>,
3636
last_change: String,
3737
repo: String,
3838
commits: String,
@@ -102,12 +102,12 @@ impl fmt::Display for Info {
102102
"Author: "
103103
};
104104

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

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

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

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

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

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

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

596598
// get only authors without their commit count
597599
// and string "'" prefix and suffix
598-
let authors: Vec<String> = authors
600+
let authors: Vec<(String, usize, usize)> = authors
599601
.into_iter()
600-
.map(|(author, _)| author.trim_matches('\'').to_string())
602+
.map(|(author, count)| (author.trim_matches('\'').to_string(), count, count*100/total_commits))
601603
.collect();
602604

603605
authors

0 commit comments

Comments
 (0)