Skip to content

Commit

Permalink
fix: add go to config message and show both stderr and stdout in gith…
Browse files Browse the repository at this point in the history
…ub 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
  • Loading branch information
humbertoyusta authored and olegklimov committed Dec 20, 2024
1 parent 38ab999 commit e0d100b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/integrations/integr_github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<Value>(&stdout) {
Ok(Value::Array(arr)) => {
let row_count = arr.len();
Expand All @@ -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(),
Expand Down
23 changes: 15 additions & 8 deletions src/integrations/integr_gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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::<Value>(&stdout) {
Ok(Value::Array(arr)) => {
let row_count = arr.len();
Expand All @@ -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(),
Expand Down

0 comments on commit e0d100b

Please sign in to comment.