From c39e51b401d42109a6a63ac62ce915f4e5c93213 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Thu, 23 Nov 2023 08:11:10 +0800 Subject: [PATCH] update Command output parser --- src/handler/workflowExecutor.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/handler/workflowExecutor.ts b/src/handler/workflowExecutor.ts index 9f0ae77..8462974 100644 --- a/src/handler/workflowExecutor.ts +++ b/src/handler/workflowExecutor.ts @@ -124,6 +124,14 @@ export class WorkflowRunner { if (isStart) { contentStr = outputWitchCache.substring(startPos+9, endPos); curPos = endPos+7; + + try { + const contentObj = JSON.parse(contentStr); + if (contentObj && contentObj.result) { + contentStr = contentObj.result; + } + } catch (error) { + } } else { contentStr = outputWitchCache.substring(startPos2, endPos+3); curPos = endPos+3; @@ -135,6 +143,17 @@ export class WorkflowRunner { return outputResult; } + private _parseLastCommandOutput(outputStr: string): string { + const startPos = outputStr.lastIndexOf('<>'); + const endPos = outputStr.lastIndexOf('<>'); + + if (startPos === -1 || endPos === -1 || endPos < startPos) { + return ''; + } + + return outputStr.substring(startPos+9, endPos); + } + private async _runCommand(commandWithArgs: string, commandEnvs: any): Promise<[CommandResult | undefined, string]> { const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath() || ""; let commandOutput = ""; @@ -254,7 +273,16 @@ export class WorkflowRunner { const [commandResult, commandAnswer] = await this._runCommand(workflowCommand, workflowEnvs); if (commandResult && commandResult.exitCode === 0) { - const resultOut = commandAnswer === "" ? "success" : commandAnswer; + const lastOutput = this._parseLastCommandOutput(commandResult.stdout); + let resultOut = commandAnswer === "" ? "success" : commandAnswer; + + try { + const lastOutputObj = JSON.parse(lastOutput); + if (lastOutputObj && lastOutputObj.result) { + resultOut = lastOutputObj.result; + } + } catch (error) {} + let logHash = await insertDevChatLog(message, message.text, resultOut); if (!logHash) { logHash = "";