-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathpoll_results.rs
More file actions
82 lines (71 loc) · 2.58 KB
/
poll_results.rs
File metadata and controls
82 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use console::style;
use crate::api_client::CodSpeedAPIClient;
use crate::cli::run::helpers::benchmark_display::build_benchmark_table;
use crate::prelude::*;
use crate::upload::{UploadResult, poll_run_report};
#[allow(clippy::borrowed_box)]
pub async fn poll_results(
api_client: &CodSpeedAPIClient,
upload_result: &UploadResult,
output_json: bool,
) -> Result<()> {
let response = poll_run_report(api_client, upload_result).await?;
let report = response.run.head_reports.into_iter().next();
if let Some(report) = report {
if let Some(impact) = report.impact {
let rounded_impact = (impact * 100.0).round();
let (arrow, impact_text) = if impact > 0.0 {
(
style("\u{25B2}").green(),
style(format!("+{rounded_impact}%")).green().bold(),
)
} else if impact < 0.0 {
(
style("\u{25BC}").red(),
style(format!("{rounded_impact}%")).red().bold(),
)
} else {
(
style("\u{25CF}").dim(),
style(format!("{rounded_impact}%")).dim().bold(),
)
};
let allowed = (response.allowed_regression * 100.0).round();
info!("{arrow} Impact: {impact_text} (allowed regression: -{allowed}%)");
} else {
info!(
"{} No impact detected, reason: {}",
style("\u{25CB}").dim(),
report.conclusion
);
}
}
if output_json {
// TODO: Refactor `log_json` to avoid having to format the json manually
// We could make use of structured logging for this https://docs.rs/log/latest/log/#structured-logging
log_json!(format!(
"{{\"event\": \"run_finished\", \"run_id\": \"{}\"}}",
upload_result.run_id
));
}
if !response.run.results.is_empty() {
end_group!();
start_group!("Benchmark results");
let table = build_benchmark_table(&response.run.results);
info!("\n{table}");
if output_json {
for result in response.run.results {
log_json!(format!(
"{{\"event\": \"benchmark_ran\", \"name\": \"{}\", \"time\": \"{}\"}}",
result.benchmark.name, result.value
));
}
}
info!(
"\n{} {}",
style("View full report:").dim(),
style(response.run.url).blue().bold().underlined()
);
}
Ok(())
}