All files / src/commands/review localReviewHandlers.js

100% Statements 61/61
100% Branches 12/12
100% Functions 1/1
100% Lines 61/61

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 623x 3x 3x 3x 3x 3x 3x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 7x 7x 7x 3x 3x 3x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 6x 1x 1x 1x 2x 2x 6x 1x 1x 1x 1x 1x 1x 2x 2x 6x 1x 1x 1x 1x 1x 32x 32x 3x 3x 3x 3x  
const {
  getWorkspaceRoot,
  getCriticalIssueCount,
  logIssues,
  showWorkspaceRequiredError,
} = require("./shared");
 
function createLocalReviewHandler({
  vscodeApi,
  logger,
  codeReviewPanel,
  prReviewService,
  staged,
  commandName,
  startLogMessage,
  startUserMessage,
}) {
  return async () => {
    try {
      const workspaceRoot = getWorkspaceRoot(vscodeApi);
      if (!workspaceRoot) {
        showWorkspaceRequiredError(vscodeApi);
        return;
      }
 
      logger.info(startLogMessage);
      vscodeApi.window.showInformationMessage(startUserMessage);
      codeReviewPanel.showReviewStarted();
 
      const result = await prReviewService.reviewLocalChanges(
        workspaceRoot,
        staged,
      );
 
      if (result.issues.length === 0) {
        vscodeApi.window.showInformationMessage(result.message);
        return;
      }
 
      const criticalCount = getCriticalIssueCount(result);
      if (criticalCount > 0) {
        vscodeApi.window.showWarningMessage(
          `${result.issues.length} issue(s) - ${criticalCount} critico(s)`,
        );
      } else {
        vscodeApi.window.showInformationMessage(result.message);
      }
 
      logIssues(logger, result);
    } catch (error) {
      vscodeApi.window.showErrorMessage(
        "No se pudo completar la revisión. Revisa el Output de G-Bot para más detalle.",
      );
      logger.error(`Error en ${commandName}: ${error.message}`);
    }
  };
}
 
module.exports = {
  createLocalReviewHandler,
};