Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): create custom local logger with spinner and colors #33

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 58 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ nestify = "0.3.3"
gql_client = { git = "https://github.com/adriencaccia/gql-client-rs" }
serde_yaml = "0.9.34"
sysinfo = { version = "0.30.12", features = ["serde"] }
indicatif = "0.17.8"
atty = "0.2.14"
console = "0.15.8"

[dev-dependencies]
temp-env = { version = "0.3.6", features = ["async_closure"] }
Expand Down
56 changes: 45 additions & 11 deletions src/api_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt::Display;

use crate::prelude::*;
use crate::{app::Cli, config::CodSpeedConfig};
use console::style;
use gql_client::{Client as GQLClient, ClientConfig};
use nestify::nest;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -77,6 +80,22 @@ pub enum ReportConclusion {
MissingBaseRun,
Success,
}

impl Display for ReportConclusion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ReportConclusion::AcknowledgedFailure => {
write!(f, "{}", style("Acknowledged Failure").yellow().bold())
}
ReportConclusion::Failure => write!(f, "{}", style("Failure").red().bold()),
ReportConclusion::MissingBaseRun => {
write!(f, "{}", style("Missing Base Run").yellow().bold())
}
ReportConclusion::Success => write!(f, "{}", style("Success").green().bold()),
}
}
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FetchLocalRunReportHeadReport {
Expand All @@ -103,11 +122,19 @@ nest! {
#[serde(rename_all = "camelCase")]*
struct FetchLocalRunReportData {
repository: pub struct FetchLocalRunReportRepository {
pub runs: Vec<FetchLocalRunReportRun>,
settings: struct FetchLocalRunReportSettings {
allowed_regression: f64,
},
runs: Vec<FetchLocalRunReportRun>,
}
}
}

pub struct FetchLocalRunReportResponse {
pub allowed_regression: f64,
pub run: FetchLocalRunReportRun,
}

impl CodSpeedAPIClient {
pub async fn create_login_session(&self) -> Result<CreateLoginSessionPayload> {
let response = self
Expand Down Expand Up @@ -142,7 +169,7 @@ impl CodSpeedAPIClient {
pub async fn fetch_local_run_report(
&self,
vars: FetchLocalRunReportVars,
) -> Result<FetchLocalRunReportRun> {
) -> Result<FetchLocalRunReportResponse> {
let response = self
.gql_client
.query_with_vars_unwrap::<FetchLocalRunReportData, FetchLocalRunReportVars>(
Expand All @@ -151,15 +178,22 @@ impl CodSpeedAPIClient {
)
.await;
match response {
Ok(response) => match response.repository.runs.into_iter().next() {
Some(run) => Ok(run),
None => bail!(
"No runs found for owner: {}, name: {}, run_id: {}",
vars.owner,
vars.name,
vars.run_id
),
},
Ok(response) => {
let allowed_regression = response.repository.settings.allowed_regression;

match response.repository.runs.into_iter().next() {
Some(run) => Ok(FetchLocalRunReportResponse {
allowed_regression,
run,
}),
None => bail!(
"No runs found for owner: {}, name: {}, run_id: {}",
vars.owner,
vars.name,
vars.run_id
),
}
}
Err(err) => bail!("Failed to fetch local run report: {}", err),
}
}
Expand Down
Loading
Loading