Skip to content

Commit 97d2289

Browse files
committed
Output project sunmary in the log
1 parent 3c0b7d2 commit 97d2289

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ I made commits to `~/rust/xml_to_serde` project recently and now want to test St
5656
```shell
5757
~$ cd rust/xml_to_serde
5858
~/rust/xml_to_serde$ stackmuncher
59+
Summary (LoC/libs): Rust 1265/6, Markdown 187, Bash 16
5960
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_xml_to_serde_git_9a32520d
6061
Project added to: https://stackmuncher.com/?dev=9PdHabyyhf4KhHAE1SqdpnbAZEXTHhpkermwfPQcLeFK
6162

@@ -155,8 +156,9 @@ Example:
155156
```shell
156157
~$ stackmuncher --project "~/rust/stm_server" --emails "[email protected], [email protected]" --dryrun
157158
158-
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_stm_server_a8ff58d9
159-
Directory Profile update skipped: `--dryrun` flag.
159+
Summary (LoC/libs): Rust 12656/26, Markdown 587, PowerShell 169
160+
Stack reports: /home/mx/stackmuncher/reports/home_ubuntu_rust_stm_server_a8ff58d9
161+
Profile update: skipped with `--dryrun` flag
160162
```
161163
162164
#### Profile settings
@@ -226,7 +228,7 @@ Assuming that you have Git and a [Rust toolchain](https://www.rust-lang.org/tool
226228
```bash
227229
git clone https://github.com/stackmuncher/stm_app.git
228230
cd stm_app
229-
cargo run -- --project "path_to_any_of_your_local_projects"
231+
cargo run -- --log error --project "path_to_any_of_your_local_projects"
230232
```
231233

232234
## Bug reports and contributions

stackmuncher/src/cmd_munch.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::help;
33
use crate::signing::ReportSignature;
44
use crate::submission::submit_report;
55
use futures::stream::{FuturesUnordered, StreamExt};
6+
use stackmuncher_lib::report_brief::TechOverview;
67
use stackmuncher_lib::{code_rules::CodeRules, config::Config, git, report::Report, utils::hash_str_sha1};
78
use std::path::Path;
89
use tracing::{debug, info, warn};
@@ -171,10 +172,12 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
171172
// save the sanitized report
172173
combined_report.save_as_local_file(sanitized_report_file_name, true);
173174

175+
print_combined_stats(&combined_report);
176+
174177
// check if the submission to the directory should go ahead
175178
if config.dryrun {
176179
// a dry-run was requested by the user
177-
println!(" Directory Profile update skipped: `--dryrun` flag.");
180+
println!(" Profile update: skipped with `--dryrun` flag");
178181
} else {
179182
if first_run {
180183
info!("No report submission on the first run");
@@ -198,8 +201,35 @@ pub(crate) async fn run(config: AppConfig) -> Result<(), ()> {
198201
}
199202

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

204207
Ok(())
205208
}
209+
210+
/// Prints a one-line summary of the report for the user to get an idea and not need to look up the report file
211+
/// E.g. `Summary (LoC/libs): Rust 12656/26, Markdown 587, PowerShell 169`
212+
fn print_combined_stats(report: &Report) {
213+
let report = report.get_overview();
214+
215+
// get a summary and sort the stack by LoC
216+
let mut tech = report.tech.iter().collect::<Vec<&TechOverview>>();
217+
tech.sort_unstable_by(|a, b| b.loc.cmp(&a.loc));
218+
219+
// prepare a single line of per-tech stats
220+
let per_tech_stats = tech
221+
.iter()
222+
.map(|t| {
223+
// only include libs count if there are any
224+
let libs = if t.libs > 0 {
225+
["/", t.libs.to_string().as_str()].concat()
226+
} else {
227+
String::new()
228+
};
229+
230+
[t.language.as_str(), " ", t.loc.to_string().as_str(), libs.as_str()].concat()
231+
})
232+
.collect::<Vec<String>>();
233+
let per_tech_stats = per_tech_stats.as_slice().join(", ");
234+
println!(" Summary (LoC/libs): {}", per_tech_stats);
235+
}

stackmuncher_lib/src/report_brief.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl super::tech::Tech {
135135
impl super::report::Report {
136136
/// Returns an abridged version of Self in the form of ProjectReportOverview.
137137
/// Calculation of `libs` is not very accurate. See comments inside the body.
138-
pub(crate) fn get_overview(&self) -> ProjectReportOverview {
138+
pub fn get_overview(&self) -> ProjectReportOverview {
139139
// collect all tech data in the overview form
140140
// there may be multiple records for the same tech, e.g. Rust/.rs and Rust/.toml, so they need to be added up
141141
let mut tech_overviews: HashMap<String, TechOverview> = HashMap::new();

0 commit comments

Comments
 (0)