Skip to content

Commit

Permalink
Output project sunmary in the log
Browse files Browse the repository at this point in the history
  • Loading branch information
rimutaka committed Aug 28, 2021
1 parent 3c0b7d2 commit 97d2289
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ I made commits to `~/rust/xml_to_serde` project recently and now want to test St
```shell
~$ cd rust/xml_to_serde
~/rust/xml_to_serde$ stackmuncher
Summary (LoC/libs): Rust 1265/6, Markdown 187, Bash 16
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_xml_to_serde_git_9a32520d
Project added to: https://stackmuncher.com/?dev=9PdHabyyhf4KhHAE1SqdpnbAZEXTHhpkermwfPQcLeFK

Expand Down Expand Up @@ -155,8 +156,9 @@ Example:
```shell
~$ stackmuncher --project "~/rust/stm_server" --emails "max@onebro.me, rimutaka@onebro.me" --dryrun
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_stm_server_a8ff58d9
Directory Profile update skipped: `--dryrun` flag.
Summary (LoC/libs): Rust 12656/26, Markdown 587, PowerShell 169
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_stm_server_a8ff58d9
Profile update: skipped with `--dryrun` flag
```
#### Profile settings
Expand Down Expand Up @@ -226,7 +228,7 @@ Assuming that you have Git and a [Rust toolchain](https://www.rust-lang.org/tool
```bash
git clone https://github.com/stackmuncher/stm_app.git
cd stm_app
cargo run -- --project "path_to_any_of_your_local_projects"
cargo run -- --log error --project "path_to_any_of_your_local_projects"
```

## Bug reports and contributions
Expand Down
34 changes: 32 additions & 2 deletions stackmuncher/src/cmd_munch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::help;
use crate::signing::ReportSignature;
use crate::submission::submit_report;
use futures::stream::{FuturesUnordered, StreamExt};
use stackmuncher_lib::report_brief::TechOverview;
use stackmuncher_lib::{code_rules::CodeRules, config::Config, git, report::Report, utils::hash_str_sha1};
use std::path::Path;
use tracing::{debug, info, warn};
Expand Down Expand Up @@ -171,10 +172,12 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
// save the sanitized report
combined_report.save_as_local_file(sanitized_report_file_name, true);

print_combined_stats(&combined_report);

// check if the submission to the directory should go ahead
if config.dryrun {
// a dry-run was requested by the user
println!(" Directory Profile update skipped: `--dryrun` flag.");
println!(" Profile update: skipped with `--dryrun` flag");
} else {
if first_run {
info!("No report submission on the first run");
Expand All @@ -198,8 +201,35 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
}

// print the location of the reports
println!(" Stack reports: {}", report_dir.to_string_lossy());
println!(" Stack reports: {}", report_dir.to_string_lossy());
info!("Repo processed in {}ms", instant.elapsed().as_millis());

Ok(())
}

/// Prints a one-line summary of the report for the user to get an idea and not need to look up the report file
/// E.g. `Summary (LoC/libs): Rust 12656/26, Markdown 587, PowerShell 169`
fn print_combined_stats(report: &Report) {
let report = report.get_overview();

// get a summary and sort the stack by LoC
let mut tech = report.tech.iter().collect::<Vec<&TechOverview>>();
tech.sort_unstable_by(|a, b| b.loc.cmp(&a.loc));

// prepare a single line of per-tech stats
let per_tech_stats = tech
.iter()
.map(|t| {
// only include libs count if there are any
let libs = if t.libs > 0 {
["/", t.libs.to_string().as_str()].concat()
} else {
String::new()
};

[t.language.as_str(), " ", t.loc.to_string().as_str(), libs.as_str()].concat()
})
.collect::<Vec<String>>();
let per_tech_stats = per_tech_stats.as_slice().join(", ");
println!(" Summary (LoC/libs): {}", per_tech_stats);
}
2 changes: 1 addition & 1 deletion stackmuncher_lib/src/report_brief.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl super::tech::Tech {
impl super::report::Report {
/// Returns an abridged version of Self in the form of ProjectReportOverview.
/// Calculation of `libs` is not very accurate. See comments inside the body.
pub(crate) fn get_overview(&self) -> ProjectReportOverview {
pub fn get_overview(&self) -> ProjectReportOverview {
// collect all tech data in the overview form
// there may be multiple records for the same tech, e.g. Rust/.rs and Rust/.toml, so they need to be added up
let mut tech_overviews: HashMap<String, TechOverview> = HashMap::new();
Expand Down

0 comments on commit 97d2289

Please sign in to comment.