From b82f068c8cca43dddf7500e9dd57e2c592399a83 Mon Sep 17 00:00:00 2001 From: sanish-bruno Date: Thu, 22 Jan 2026 20:32:26 +0530 Subject: [PATCH] refactor: remove unused hook execution function and clean up code - Eliminated the executeHooksForLevel function from run-single-request.js and network/index.js to streamline hook management. - Updated comments for clarity and consistency in the remaining hook execution functions. --- .../src/runner/run-single-request.js | 16 ----- .../bruno-electron/src/ipc/network/index.js | 62 +------------------ 2 files changed, 1 insertion(+), 77 deletions(-) diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 230ef590f..a6d0aca45 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -175,21 +175,6 @@ const runSingleRequest = async function ( // Extract hooks for all levels const { collectionHooks, folderHooks, requestHooks } = extractHooks(collection, request, requestTreePath); - // Helper function to initialize and execute hooks at runtime using shared executor - const executeHooksForLevel = async (hooksFile, hookEvent, eventData) => { - return HooksExecutor.executeHooksForLevel(hooksFile, hookEvent, eventData, { - request, - envVariables, - runtimeVariables, - collectionPath, - onConsoleLog, - processEnvVars, - scriptingConfig, - runRequestByItemPathname: runSingleRequestByPathname, - collectionName - }); - }; - // Helper function to execute all hooks using consolidated approach const executeAllHooksConsolidated = async (extractedHooks, hookEvent, eventData) => { return HooksExecutor.executeAllHookLevels(extractedHooks, hookEvent, eventData, { @@ -596,7 +581,6 @@ const runSingleRequest = async function ( if (request.ntlmConfig) { axiosInstance = NtlmClient(request.ntlmConfig, axiosInstance.defaults); - delete request.ntlmConfig; } diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 4a7f23b10..3c262c81d 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -446,72 +446,12 @@ const registerNetworkIpc = (mainWindow) => { }); }; - /** - * Execute hooks for a specific level at runtime using shared executor - * Initializes HookManager, executes the hook event, and disposes immediately - * @param {string} hooksFile - Hooks file content for this level - * @param {string} hookEvent - Hook event to trigger (e.g., HOOK_EVENTS.HTTP_BEFORE_REQUEST) - * @param {object} eventData - Data to pass to hook handlers - * @param {object} options - Configuration options - * @param {object} options.request - Request object - * @param {object} options.envVars - Environment variables - * @param {object} options.runtimeVariables - Runtime variables - * @param {string} options.collectionPath - Collection path - * @param {function} options.onConsoleLog - Console log callback - * @param {object} options.processEnvVars - Process environment variables - * @param {object} options.scriptingConfig - Scripting configuration - * @param {function} options.runRequestByItemPathname - Function to run requests - * @param {string} options.collectionName - Collection name - * @param {string} options.requestUid - Request UID (for error notifications) - * @param {string} options.itemUid - Item UID (for error notifications) - * @param {string} options.collectionUid - Collection UID (for error notifications) - * @param {boolean} options.runInBackground - Whether running in background - * @param {function} options.notifyScriptExecution - Function to notify script execution - */ - const executeHooksForLevel = async (hooksFile, hookEvent, eventData, options) => { - if (!hooksFile || !hooksFile.trim()) { - return; - } - - try { - // Use shared executor for hook execution - const result = await HooksExecutor.executeHooksForLevel(hooksFile, hookEvent, eventData, { - request: options.request || {}, - envVariables: options.envVars, - runtimeVariables: options.runtimeVariables, - collectionPath: options.collectionPath, - onConsoleLog: options.onConsoleLog, - processEnvVars: options.processEnvVars, - scriptingConfig: options.scriptingConfig, - runRequestByItemPathname: options.runRequestByItemPathname, - collectionName: options.collectionName - }); - - return result; - } catch (error) { - console.error(`Error executing hooks for ${hookEvent}:`, error); - options.onConsoleLog?.('error', [`Error executing hooks for ${hookEvent}: ${error.message}`]); - if (!options.runInBackground && options.notifyScriptExecution && typeof options.notifyScriptExecution === 'function') { - options.notifyScriptExecution({ - channel: 'main:run-request-event', - basePayload: { - requestUid: options.requestUid, - collectionUid: options.collectionUid, - itemUid: options.itemUid - }, - scriptType: 'hooks', - error - }); - } - } - }; - /** * Execute all hooks using consolidated approach * @param {object} extractedHooks - Hooks from all levels * @param {string} hookEvent - Hook event to trigger * @param {object} eventData - Data to pass to hook handlers - * @param {object} options - Configuration options (same as executeHooksForLevel) + * @param {object} options - Configuration options */ const executeAllHooksConsolidated = async (extractedHooks, hookEvent, eventData, options) => { try {