From e636978c0e7b7ce54e5682970a9e5c816045e185 Mon Sep 17 00:00:00 2001 From: jk-gan Date: Thu, 5 Jan 2023 16:47:15 +0800 Subject: [PATCH] feat: display debug --- Cargo.toml | 2 +- src/graphql/application.rs | 3 +++ src/graphql/changelog.rs | 3 +++ src/graphql/deployment.rs | 7 +++++++ src/graphql/mod.rs | 11 +++++++++-- src/graphql/pipeline.rs | 9 +++++++++ src/main.rs | 15 ++++++++++++++- 7 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30b1b8a92..187c7f483 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ lto = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4", features = ["derive", "wrap_help"] } +clap = { version = "4", features = ["derive", "wrap_help", "cargo"] } clap_complete = { version = "4" } dirs = "4.0" indicatif = "0.17.0" diff --git a/src/graphql/application.rs b/src/graphql/application.rs index a605fda85..a0fb1696d 100644 --- a/src/graphql/application.rs +++ b/src/graphql/application.rs @@ -1,6 +1,7 @@ use super::QueryClient; use crate::error::APIError; use graphql_client::{GraphQLQuery, Response}; +use log::debug; #[derive(GraphQLQuery)] #[graphql( @@ -25,6 +26,8 @@ impl ApplicationsQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } diff --git a/src/graphql/changelog.rs b/src/graphql/changelog.rs index 68d41d93e..4f8013716 100644 --- a/src/graphql/changelog.rs +++ b/src/graphql/changelog.rs @@ -1,6 +1,7 @@ use super::QueryClient; use crate::error::APIError; use graphql_client::{GraphQLQuery, Response}; +use log::debug; #[derive(GraphQLQuery)] #[graphql( @@ -46,6 +47,8 @@ impl ChangelogsQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } diff --git a/src/graphql/deployment.rs b/src/graphql/deployment.rs index e5eb67dd6..d4e8e4466 100644 --- a/src/graphql/deployment.rs +++ b/src/graphql/deployment.rs @@ -1,6 +1,7 @@ use super::QueryClient; use crate::error::APIError; use graphql_client::{GraphQLQuery, Response}; +use log::debug; #[derive(GraphQLQuery)] #[graphql( @@ -32,6 +33,8 @@ impl CdPipelinesQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } @@ -70,6 +73,8 @@ impl CdPipelineQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } @@ -118,6 +123,8 @@ impl ExecuteCdPipeline { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs index 2e3b16556..bec1bca62 100644 --- a/src/graphql/mod.rs +++ b/src/graphql/mod.rs @@ -20,7 +20,8 @@ use crate::{ error::APIError, telemetry::{self, TelemetryData, TelemetryEvent}, }; -use graphql_client::{reqwest::post_graphql, GraphQLQuery, Response}; +use graphql_client::{GraphQLQuery, Response}; +use log::debug; use reqwest::header; use wukong_telemetry_macro::wukong_telemetry; @@ -102,7 +103,13 @@ impl QueryClient { graphql_client::Error, ) -> Result, APIError>, ) -> Result, APIError> { - let response = post_graphql::(self.inner(), &self.api_url, variables).await?; + let body = Q::build_query(variables); + let request = self.inner().post(&self.api_url).json(&body); + + debug!("request: {:?}", request); + debug!("graphQL query: \n{}", body.query); + + let response: Response = request.send().await?.json().await?; if let Some(errors) = response.errors.clone() { let first_error = errors[0].clone(); diff --git a/src/graphql/pipeline.rs b/src/graphql/pipeline.rs index b6f5daabe..d53ae3956 100644 --- a/src/graphql/pipeline.rs +++ b/src/graphql/pipeline.rs @@ -1,6 +1,7 @@ use super::QueryClient; use crate::error::APIError; use graphql_client::{GraphQLQuery, Response}; +use log::debug; #[derive(GraphQLQuery)] #[graphql( @@ -38,6 +39,8 @@ impl PipelinesQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } @@ -75,6 +78,8 @@ impl PipelineQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } @@ -112,6 +117,8 @@ impl MultiBranchPipelineQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } @@ -148,6 +155,8 @@ impl CiStatusQuery { }) .await?; + debug!("response: {:?}", &response); + Ok(response) } } diff --git a/src/main.rs b/src/main.rs index 5fee2e586..f57f8ff30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,13 +15,14 @@ mod telemetry; use crate::auth::refresh_tokens; use app::{App, ConfigState}; use chrono::{DateTime, Local}; +use clap::crate_version; use commands::{ completion::handle_completion, init::handle_init, login::handle_login, CommandGroup, }; use config::{AuthConfig, Config, CONFIG_FILE}; use error::CliError; use human_panic::setup_panic; -use log::{error, info}; +use log::{debug, error, info}; use openidconnect::RefreshToken; use output::error::ErrorOutput; use std::process; @@ -153,6 +154,18 @@ async fn run() -> Result { context.application = Some(application.clone()); } + debug!("current cli version: {}", crate_version!()); + debug!("current application: {:?}", &context.application); + debug!( + "current API URL: {:?}", + match &app.config { + ConfigState::InitialisedButUnAuthenticated(config) + | ConfigState::InitialisedAndAuthenticated(config) => Some(&config.core.wukong_api_url), + ConfigState::Uninitialised => None, + } + ); + debug!("current calling user: {:?}", &context.account); + match app.cli.command_group { CommandGroup::Pipeline(pipeline) => { must_init_and_login!(app.config, pipeline.handle_command(context).await)