mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-26 14:15:52 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user