github_analytics/print_data/
mod.rs1use std::collections::HashMap;
2
3use crate::models::Interaction;
4
5pub fn display_summary(repo_info: &HashMap<String, Vec<Interaction>>) {
24 let mut lines: Vec<Vec<String>> = vec![vec![
26 "Repo".to_owned(),
27 "PRs opened".to_owned(),
28 "PRs merged".to_owned(),
29 "Issues opened".to_owned(),
30 "Issues closed".to_owned(),
31 ]];
32 repo_info.into_iter().for_each(|(repo, interactions)| {
34 let mut issues_opened = 0;
35 let mut issues_closed = 0;
36 let mut prs_opened = 0;
37 let mut prs_closed = 0;
38
39 interactions.into_iter().for_each(|interaction| {
40 match interaction.interaction_type.as_str() {
41 "pr created" => prs_opened += 1,
42 "pr ended" => prs_closed += 1,
43 "issue created" => issues_opened += 1,
44 "issue ended" => issues_closed += 1,
45 _ => panic!("Unknown interaction type"),
46 }
47 });
48 lines.push(
49 [
50 repo.to_owned(),
51 prs_opened.to_string(),
52 prs_closed.to_string(),
53 issues_opened.to_string(),
54 issues_closed.to_string(),
55 ]
56 .to_vec(),
57 );
58 });
59 let mut out = Vec::new();
60 text_tables::render(&mut out, lines).unwrap();
62 println!("{}", std::str::from_utf8(&out).unwrap());
64}