From e0d100b268f77985bac3449a8b521232ba504852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Humberto=20Yusta=20G=C3=B3mez?= Date: Thu, 19 Dec 2024 13:29:03 +0100 Subject: [PATCH] fix: add go to config message and show both stderr and stdout in github and gitlab Needed to show both stdout and stderr, because glab cli puts some extra info in stderr like there is a new version, but command still works and stdout is fine --- src/integrations/integr_github.rs | 23 +++++++++++++++-------- src/integrations/integr_gitlab.rs | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/integrations/integr_github.rs b/src/integrations/integr_github.rs index 9d366a2f8..b9d9fb7d1 100644 --- a/src/integrations/integr_github.rs +++ b/src/integrations/integr_github.rs @@ -10,6 +10,7 @@ use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ContextEnum, ChatMessage, ChatContent, ChatUsage}; use crate::files_correction::to_pathbuf_normalize; +use crate::integrations::go_to_configuration_message; use crate::tools::tools_description::Tool; use serde_json::Value; use crate::integrations::integr_abstract::{IntegrationCommon, IntegrationConfirmation, IntegrationTrait}; @@ -90,23 +91,20 @@ impl Tool for ToolGithub { if gh_binary_path.is_empty() { gh_binary_path = "gh".to_string(); } - let output = Command::new(gh_binary_path) + let output = Command::new(&gh_binary_path) .args(&command_args) .current_dir(&to_pathbuf_normalize(&project_dir)) .env("GH_TOKEN", &self.settings_github.gh_token) .env("GITHUB_TOKEN", &self.settings_github.gh_token) .output() .await - .map_err(|e| e.to_string())?; + .map_err(|e| format!("!{}, {} failed:\n{}", + go_to_configuration_message("github"), gh_binary_path, e.to_string()))?; + let stdout = String::from_utf8_lossy(&output.stdout).to_string(); let stderr = String::from_utf8_lossy(&output.stderr).to_string(); - if !stderr.is_empty() { - error!("Error: {:?}", stderr); - return Err(stderr); - } - - let content = if stdout.starts_with("[") { + let stdout_content = if stdout.starts_with("[") { match serde_json::from_str::(&stdout) { Ok(Value::Array(arr)) => { let row_count = arr.len(); @@ -120,6 +118,15 @@ impl Tool for ToolGithub { } else { stdout }; + + let mut content = String::new(); + if !stdout_content.is_empty() { + content.push_str(format!("stdout:\n{}\n", stdout_content).as_str()); + } + if !stderr.is_empty() { + content.push_str(format!("stderr:\n{}\n", stderr).as_str()); + } + let mut results = vec![]; results.push(ContextEnum::ChatMessage(ChatMessage { role: "tool".to_string(), diff --git a/src/integrations/integr_gitlab.rs b/src/integrations/integr_gitlab.rs index 33f32babe..32f1b6b72 100644 --- a/src/integrations/integr_gitlab.rs +++ b/src/integrations/integr_gitlab.rs @@ -10,6 +10,7 @@ use serde_json::Value; use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ContextEnum, ChatMessage, ChatContent, ChatUsage}; use crate::files_correction::to_pathbuf_normalize; +use crate::integrations::go_to_configuration_message; use crate::tools::tools_description::Tool; use crate::integrations::integr_abstract::{IntegrationCommon, IntegrationConfirmation, IntegrationTrait}; @@ -89,22 +90,19 @@ impl Tool for ToolGitlab { if glab_binary_path.is_empty() { glab_binary_path = "glab".to_string(); } - let output = Command::new(glab_binary_path) + let output = Command::new(&glab_binary_path) .args(&command_args) .current_dir(&to_pathbuf_normalize(&project_dir)) .env("GITLAB_TOKEN", &self.settings_gitlab.glab_token) .output() .await - .map_err(|e| e.to_string())?; + .map_err(|e| format!("!{}, {} failed:\n{}", + go_to_configuration_message("gitlab"), glab_binary_path, e.to_string()))?; + let stdout = String::from_utf8_lossy(&output.stdout).to_string(); let stderr = String::from_utf8_lossy(&output.stderr).to_string(); - if !stderr.is_empty() { - error!("Error: {:?}", stderr); - return Err(stderr); - } - - let content = if stdout.starts_with("[") { + let stdout_content = if stdout.starts_with("[") { match serde_json::from_str::(&stdout) { Ok(Value::Array(arr)) => { let row_count = arr.len(); @@ -118,6 +116,15 @@ impl Tool for ToolGitlab { } else { stdout }; + + let mut content = String::new(); + if !stdout_content.is_empty() { + content.push_str(format!("stdout:\n{}\n", stdout_content).as_str()); + } + if !stderr.is_empty() { + content.push_str(format!("stderr:\n{}\n", stderr).as_str()); + } + let mut results = vec![]; results.push(ContextEnum::ChatMessage(ChatMessage { role: "tool".to_string(),